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.
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
if n == 1:
    print(0)
    exit()
c = Counter(a)
pow_2 = set([pow(2, i) for i in range(31)])
min_L = min(a)
flag = False
for aa in a:
    if aa%min_L != 0 or aa//min_L not in pow_2:
        flag = True
        break
ans = 0
if flag:
    for aa in c.keys():
        aaa = aa
        while aaa > 1:
            ans += c[aa]
            aaa //= 2
else:
    if len(a) == 2:
        bal = a[0]
    else:
        bal = sorted(a)[1]
    for aa in c.keys():
        if bal > aa:
            t = bal // aa
        elif bal < aa:
            t = aa // bal
        else:
            continue
        while t != 1:
            t //= 2
            ans += c[aa]
print(ans)
