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.

# Standard modules
import sys

# Additional modules


class Chem:
    """ Chem representation """
    MAX = 100001

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

        self.n = args[0]
        self.list = args[1]

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

                new_valid.add(vol)
                stp[vol] += steps
            prev = vol
            vol >>= 1
            steps += 1
        if not first:
            valid.intersection_update(new_valid)
        else:
            valid.update(new_valid)

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

        valid = set()
        stp = [0] * self.MAX
        for n in self.list:
            self.decant(valid, stp, n)

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

        return str(result)



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()



if __name__ == "__main__":

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