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.
import sys
from collections import *
from itertools import *
from math import *
from array import *
from functools import lru_cache
import heapq
import bisect
import random
import io, os
from bisect import *

if sys.hexversion == 50924784:
    sys.stdin = open('cfinput.txt')

# input = sys.stdin.readline
# input_int = sys.stdin.buffer.readline
# RI = lambda: map(int, input_int().split())
# RS = lambda: input().strip().split()
# RILST = lambda: list(RI())

# RI = lambda: map(int, sys.stdin.buffer.readline().split())
# RS = lambda: sys.stdin.readline().strip().split()
# RILST = lambda: list(RI())

# input = sys.stdin.buffer.readline
# RI = lambda: map(int, input().split())
# RS = lambda: map(bytes.decode, input().strip().split())
# RILST = lambda: list(RI())

RI = lambda: map(int, sys.stdin.buffer.readline().split())
RS = lambda: map(bytes.decode, sys.stdin.buffer.readline().strip().split())
RILST = lambda: list(RI())

MOD = 10 ** 9 + 7
"""输入https://codeforces.com/problemset/problem/558/C

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

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


#  	 ms
def solve(n, a):
    # cnt = [0] * (max(a) + 1)
    # for v in a:
    #     cnt[v] += 1
    cnt = Counter(a)
    if len(cnt) <= 1:
        return 0
    cnt = sorted([(k, v) for k, v in cnt.items()], key=lambda x: x[1], reverse=True)

    @lru_cache
    def dfs(a, b):
        if a == b:
            return 0
        elif a < b:
            s = b // a
            if s * a == b and s & (s - 1) == 0:
                return int(log2(s))
        elif a > b:
            s = a // b
            if s * b == a and s & (s - 1) == 0:
                return int(log2(s))

        ans = 0
        while b and b & 1 == 0:
            ans += 1
            b >>= 1
        while a and a != b:
            ans += 1
            a //= 2
            if a == b:
                return ans
        return inf

    top = sum(dfs(k, 1) * v for k, v in cnt)

    k, v = cnt[0]
    vis = {k: 0}
    q = deque([k])
    step = 0
    while q:
        step += v
        if step + n - v > top:
            break
        for _ in range(len(q)):
            u = q.popleft()
            for v in u << 1, u >> 1:
                if v and v not in vis:
                    vis[v] = step
                    q.append(v)
    # print(vis,top)
    s = v
    for i in range(1, len(cnt)):
        k, v = cnt[i]
        s += v
        pre = vis
        vis = {}

        for a, b in pre.items():
            step = dfs(k, a)
            if step == 0:
                vis[a] = b
            else:
                step = step * v + b
                if step +n-s <= top:
                    vis[a] = step

        #     print(i, cnt[i], vis,step,a,b,s)
        # print(i,cnt[i],vis)
    print(min(vis.values()))


if __name__ == '__main__':
    n, = RI()
    a = RILST()

    solve(n, a)
