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.
'''
https://codeforces.com/problemset/problem/558/C

输入 n(≤1e5) 和一个长为 n 的数组 a (1≤a[i]≤1e5)。
每次操作你可以将某个 a[i] 乘二或除二（下取整）。
输出至少需要多少次操作，可以让 a 的所有数都相同。

你能做到 O(nlogU) 的时间复杂度吗？ U=max(a)

输入
3
4 8 2
输出 2
解释 都变成 4。

输入
3
3 5 6
输出 5
解释 都变成 1。
'''

from itertools import *
from collections import *
from math import *
from heapq import *
from functools import *
from bisect import *
from random import *
import sys
from typing import List

input = sys.stdin.readline


def solve():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = Counter()
    sum = Counter()
    mv = max(a)
    for i, v in enumerate(a):
        cnt[v] += 1
        # 变大
        count = 0
        tmp = v
        while tmp < mv:
            tmp *= 2
            count += 1
            cnt[tmp] += 1
            sum[tmp] += count
        # 变小
        count = 0
        tmp = v
        while tmp:
            tmp //= 2
            count += 1
            cnt[tmp] += 1
            sum[tmp] += count

    res = inf
    # 判断某个值是否出现了n次
    for k, v in cnt.items():
        if v == n:
            res = min(res, sum[k])
    print(res)


solve()
