Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment.

Amr has *n* different types of chemicals. Each chemical *i* has an initial volume of *a*<sub class="lower-index">*i*</sub> liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So his task is to make all the chemicals volumes equal.

To do this, Amr can do two different kind of operations. 
 -  Choose some chemical *i* and double its current volume so the new volume will be 2*a*<sub class="lower-index">*i*</sub> -  Choose some chemical *i* and divide its volume by two (integer division) so the new volume will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/527470887c95577094d0c6c100f6bec4842e6d29.png" style="max-width: 100.0%;max-height: 100.0%;"/> 
Suppose that each chemical is contained in a vessel of infinite volume. Now Amr wonders what is the minimum number of operations required to make all the chemicals volumes equal?
The first line contains one number *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>), the number of chemicals.

The second line contains *n* space separated integers *a*<sub class="lower-index">*i*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">5</sup>), representing the initial volume of the *i*-th chemical in liters.
#!/usr/bin/env python
# 558C_chem.py - Codeforces.com 558C Chem quiz
#
# Copyright (C) 2015 Sergey
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Suppose that each chemical is contained in a vessel of infinite volume.
Now Amr wonders what is the minimum number of operations required to make
all the chemicals volumes equal?
Input

The first line contains one number n, the number of chemicals.

The second line contains n space separated integers ai, representing the
initial volume of the ith chemical in liters.
Output

Output one integer the minimum number of operations required to make all
the chemicals volumes equal.
"""

# Standard modules
import unittest
import sys
import re
import random
import bisect
import array

# Additional modules


###############################################################################
# Chem Class
###############################################################################


class Chem:
    """ Chem representation """

    def __init__(self, args):
        """ Default constructor """

        self.n = args[0]
        self.list = sorted(args[1])
        self.max = self.list[-1]

    def decant(self, valid, stp, vol, max):
        new_valid = set()
        first = 1 if not valid else 0
        steps = 0
        prev = None
        while vol > 0:
            if (first or vol in valid) and (prev is None or prev % 2 == 1):
                ssteps = steps + 1
                svol = vol * 2
                while svol <= max:
                    if first:
                        valid.add(svol)
                        stp[svol] = ssteps
                    elif svol in valid:
                        new_valid.add(svol)
                        stp[svol] += ssteps
                    else:
                        break
                    svol *= 2
                    ssteps += 1
            if first:
                valid.add(vol)
                stp[vol] = steps
            elif vol in valid:
                new_valid.add(vol)
                stp[vol] += steps
            prev = vol
            vol >>= 1
            steps += 1
        if not first:
            valid.intersection_update(new_valid)

    def calculate(self):
        """ Main calcualtion function of the class """

        valid = set()
        stp = dict()
        for n in self.list:
            self.decant(valid, stp, n, self.max)

        result = None
        for n in valid:
            if result is None or result > stp[n]:
                result = stp[n]

        return str(result)


###############################################################################
# Helping classes
###############################################################################


###############################################################################
# Executable code
###############################################################################


def get_inputs(test_inputs=None):

    it = iter(test_inputs.split("\n")) if test_inputs else None

    def uinput():
        """ Unit-testable input function wrapper """
        if it:
            return next(it)
        else:
            return sys.stdin.readline()

    # Getting string inputs. Place all uinput() calls here
    num = int(uinput())
    nums = map(int, uinput().split())

    # Decoding inputs into a list
    return [num, nums]


def calculate(test_inputs=None):
    """ Base class calculate method wrapper """
    return Chem(get_inputs(test_inputs)).calculate()


###############################################################################
# Unit Tests
###############################################################################


class unitTests(unittest.TestCase):

    def test_sample_tests(self):
        """ Quiz sample tests. Add \n to separate lines """

        # Sample test 1
        test = "3\n4 8 2"
        self.assertEqual(calculate(test), "2")
        self.assertEqual(get_inputs(test)[0], 3)
        self.assertEqual(list(get_inputs(test)[1]), [4, 8, 2])

        # Sample test 2
        test = "3\n3 5 6"
        self.assertEqual(calculate(test), "5")

        # Sample test 3
        test = "3\n10 4 4"
        self.assertEqual(calculate(test), "3")

    def test_timelimit_tests(self):

        # Time limit test
        imax = 100000
        test = str(imax)
        nums = [random.randint(1, 100000) for i in range(imax)]
        test += "\n" + " ".join(map(str, nums))

        import timeit

        start = timeit.default_timer()
        args = get_inputs(test)

        init = timeit.default_timer()
        d = Chem(args)

        calc = timeit.default_timer()
        d.calculate()

        stop = timeit.default_timer()
        print("\nTime Test: {0:.3f} (inp {1:.3f} init {2:.3f} calc {3:.3f})".
              format(stop-start, init-start, calc-init, stop-calc))

    def test_Chem_class__basic_functions(self):
        """ Chem class basic functions testing """

        # Constructor test
        d = Chem([3, [4, 8, 2]])
        self.assertEqual(d.list[0], 2)

        valid = set()
        stp = [0]*11
        d.decant(valid, stp, 5, 10)
        self.assertEqual(valid, {1, 2, 4, 5, 8, 10})
        self.assertEqual(stp, [0, 2, 1, 0, 2, 0, 0, 0, 3, 0, 1])

        valid = set()
        stp = [0]*11
        d.decant(valid, stp, 3, 10)
        self.assertEqual(valid, {8, 1, 2, 4, 3, 6})
        self.assertEqual(stp, [0, 1, 2, 0, 3, 0, 1, 0, 4, 0, 0])
        d.decant(valid, stp, 5, 10)
        self.assertEqual(valid, {8, 1, 2, 4})

if __name__ == "__main__":

    # Avoiding recursion limitaions
    sys.setrecursionlimit(100000)

    if sys.argv[-1] == "-ut":
        unittest.main(argv=[" "])

    # Print the result string
    sys.stdout.write(calculate())
