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
sys.setrecursionlimit(10**9)
# import random
from collections import Counter, defaultdict, deque
# from functools import lru_cache, reduce
# from itertools import accumulate,product
# from heapq import nsmallest, nlargest, heapify, heappop, heappush
# from bisect import bisect_left,bisect_right
# from sortedcontainers import SortedList
# input = sys.stdin.buffer.readline
# import re
input = sys.stdin.readline
def mp():return list(map(int,input().split()))
def it():return int(input())
import math

mod=10**9+7

def solve():
    n=it()
    nums=mp()
    MAXN=10**6
    M=10**5
    dep,sz,vis=[0]*MAXN,[0]*MAXN,defaultdict(int)
    for num in nums:
        vis[num]=1
    def dfs(root):
        if root>M:
            return 
        dep[root<<1],dep[root<<1|1]=dep[root]+1,dep[root]+1
        dfs(root<<1)
        dfs(root<<1|1)
        sz[root]=sz[root<<1]+sz[root<<1|1]+vis[root]
        return
    dfs(1)
    root=1
    for x in range(1,M+1,-1):
        if sz[x]==n:
            root=x      
            break
    s=0
    ans=math.inf
    for num in nums:
        s+=dep[num]-dep[root]
    ans=min(ans,s)
    while (root<<1)<=M:
        s+=n-2*sz[root<<1] 
        root=root<<1
        ans=min(ans,s)
    print(ans)           

    return

if __name__ == '__main__':

    # t=it()
    # for _ in range(t):
    #     solve()

    # n=it()
    # n,m,i=mp()
    # n,m=mp()
    solve()