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 ai 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 2ai
  * Choose some chemical i and divide its volume by two (integer division) so the new volume will be <image>



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?

Input

The first line contains one number n (1 ≤ n ≤ 105), the number of chemicals.

The second line contains n space separated integers ai (1 ≤ ai ≤ 105), representing the initial volume of the i-th chemical in liters.

Output

Output one integer the minimum number of operations required to make all the chemicals volumes equal.

Examples

Input

3
4 8 2


Output

2

Input

3
3 5 6


Output

5

Note

In the first sample test, the optimal solution is to divide the second chemical volume by two, and multiply the third chemical volume by two to make all the volumes equal 4.

In the second sample test, the optimal solution is to divide the first chemical volume by two, and divide the second and the third chemical volumes by two twice to make all the volumes equal 1.

import java.awt.List;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;

public class Watermelon {
	public static void main(String[] args) throws IOException{
		Main m=new Main();
		m.solve();
	}
	}
class Main{
	
	 BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	 private int[] array;
	    private int[] tempMergArr;
	    private int length;
	
	    BigInteger[] temp=new BigInteger[31];
		BigInteger x,y,z;
	    StringTokenizer stringTokenizer;

	     String next() throws IOException {
	        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
	            stringTokenizer = new StringTokenizer(reader.readLine());
	        }
	        return stringTokenizer.nextToken();
	    }

	    int nextInt() throws IOException {
	        return Integer.parseInt(next());
	    }

	    long nextLong() throws IOException {
	        return Long.parseLong(next());
	    }
	    int[] marr=null;
	    int[] BIT=new int[9];
	    int[] arr=null;
	    int[][] lcsarr=null;
	    void solve() throws IOException  {
	         int n=this.nextInt();
	         int[] arr=new int[n];
	         int max=100000;
	         for(int i=0;i<n;i++)
	        	 {
	        	 arr[i]=this.nextInt();
	        	 if(max<arr[i])
	        		 max=arr[i];
	        	 }
	         Count[] marr=new Count[100001];
	         int kcount=0;
	         for(int i=0;i<=max;i++)
	        	 marr[i]=new Count(0,0);
	         for(int i=0;i<n;i++){
	        	// System.out.println(marr[arr[i]].k);
	        	 int temp=arr[i];
	             int count=0;
	        	 int xtemp=0;
	             int xcount=0;
	        	 while(temp!=0){
	       		 xcount=count;
	             xtemp=temp;
	             while(xtemp<=100000){
		       		 
	//	       		 System.out.println(xtemp+"");
	            	 if(marr[xtemp].k!=i+1){
			       	 marr[xtemp].i++;
		        	 marr[xtemp].j+=xcount;
		        	 marr[xtemp].k=i+1;
	            	 }xtemp*=2;	
		         	 xcount++;
	//	         	 System.out.println("Hey");
	            	 
	        	 }
	        	 temp/=2;	       		count++;

	   //      	 System.out.println("Hey1");
	        	 } 	
	  //       	System.out.println("Hey2");
	      }
	         
	         int min=Integer.MAX_VALUE;
	         int mini=0;
	   //      if(n==6061)
	   //     for(int i=1;i<=max;i++)
		 //           marr[i].display();
	         for(int i=1;i<=max;i++){
	  	        if(min>marr[i].j&&marr[i].i==n)
	        		 {min=marr[i].j;mini=i;}
	         }
	         System.out.println(min);
	         }
       void recurs(int[] arr,int x){
	    }
	    static int max_LIS=0;
	   
	    public int LIS(int[] arr,int n){
	    	if(n==0)
	    		{
	    		marr[0]=1;
	    		return 1;
	    		}
	    	
	    	int current =1;
	    	for(int i=0;i<n;i++){
	    		int subproblem=0;
	    		if(marr[i]==0)
	    		{
	    			subproblem=LIS(arr,i);
	    			marr[i]=subproblem;
	    		}
	    		else{
	    		//	System.out.println("Hey");
	    			subproblem=marr[i];
	    		}
	    		
	    		System.out.println(current+" "+subproblem+" "+i);
	    		if(arr[i]<arr[n]&&current<(1+subproblem)){
	    			current=(1+subproblem);
	    		}
	    	}
	    	if(max_LIS<current)
	    		max_LIS=current;
	    	return current;
	    }
	    public int LCS1(int i,int j){
	    	System.out.println(i+" "+j+"hey");
	    	int n=0;
	    	if(i==-1||j==-1)
	    		return 0;
	    	if(arr[i]==marr[j])
	    		n=1+LCS1(i-1,j-1);
	    	else{
	    		n=Math.max(LCS1(i-1,j), LCS1(i,j-1));
	    	}
	    	return n;
	    }
	    public int LCS(int i,int j){
	    	System.out.println(i+" "+j);
	    	int n=0;
	    	if(i==-1||j==-1)
	    		return 0;
	    	if(arr[i]==marr[j])
	    		{
	    		if(i!=0&&j!=0){
	    		if(lcsarr[i-1][j-1]==0){
	    		n=1+LCS(i-1,j-1);
	    		lcsarr[i-1][j-1]=n-1;
	    		}
	    		else{
	    			n=1+lcsarr[i-1][j-1];
	    		}
	    		}
	    	else
	    		n=1+LCS(i-1,j-1);
	    		}
	    	else{
	    		int x,y=0;
	    		if(i!=0){
	    		
	    		if(lcsarr[i-1][j]==-1)
	    		{
	    			x=LCS(i-1,j);
	    			lcsarr[i-1][j]=x;
	    		}
	    		else{
	    			x=lcsarr[i-1][j];
	    		}
	    		}
	    		else
	    			x=LCS(i-1,j);
	    		if(j!=0){
	    		if(lcsarr[i][j-1]==-1){
	    		y=LCS(i,j-1);
	    		lcsarr[i][j-1]=y;
	    		}
	    		else{
	    			y=lcsarr[i][j-1];
	    		}
	    		}
	    		else
	    			y=LCS(i,j-1);
	    		n=Math.max(x, y);
	    	}
	    	return n;
	    }
	public BigInteger comb(int n,int r){
	     x=this.temp[n];
		 y=this.temp[r];
		 z=this.temp[n-r];
	//	 System.out.println(x+" "+y+" "+z);
		 BigInteger ret=x.divide(y.multiply(z));
		 return ret;
		 
	}
	public void fact(){
		this.temp[0]=BigInteger.ONE;
		this.temp[1]=BigInteger.ONE;
		for(int i=2;i<this.temp.length;i++){
			temp[i]=(temp[i-1].multiply(BigInteger.valueOf(i)));
		}
	}
	private static int gcd(int a, int b)
	{
	    while (b > 0)
	    {
	    	int temp = b;
	        b = a % b; // % is remainder
	        a = temp;
	    }
	    return a;
	}
	private static int lcm(int a, int b)
	{
	    return a * (b / gcd(a, b));
	}
	static int[] toFractionPos(int x,int y){
		int a=gcd(x,y);
		int[] arr={x/a,y/a};
		//display(arr);
		return arr;
	}
   
	static void display(int[][] arr){
		for(int i=0;i<arr.length;i++){
			for(int j=0;j<arr[i].length;j++){
				System.out.print(arr[i][j]+" ");
		}
			System.out.println();
		}
		System.out.println();
	}

	 static void display(String[] arr){
			for(int i=0;i<arr.length;i++){
				System.out.println(arr[i]+" ");
			}	
			//System.out.println();
		
	 }
	 static void display(int[] arr){
		 for(int i=0;i<arr.length;i++)
				System.out.print(arr[i]+" ");
		System.out.println();
		 }
		 static void display(double[] arr){
		 	   for(int i=0;i<arr.length;i++){
		 		   System.out.print(arr[i]+" ");
		 	   }
		 	   System.out.println();
	    }
	 static void display(char[] arr){
		// System.out.println();
		 int t=0;
			for(int i=0;i<arr.length;i++){
				if(arr[i]!='0'){t=i;break;}
			}	
			while(t!=arr.length){
				System.out.print(arr[t]);
				t++;
			}
			System.out.println();
		
		  }
	 static String str(char[] carr){
		 String str="";
		 for(int i=0;i<carr.length;i++){
			    str=str+carr[i];
			}
		 return str;
	 }
	    public void sort(int inputArr[]) {
	        this.array = inputArr;
	        this.length = inputArr.length;
	        this.tempMergArr = new int[length];
	        doMergeSort(0, length - 1);
	    }
	 
	    private void doMergeSort(int lowerIndex, int higherIndex) {
	         
	        if (lowerIndex < higherIndex) {
	            int middle = lowerIndex + (higherIndex - lowerIndex) / 2;
	            // Below step sorts the left side of the array
	            doMergeSort(lowerIndex, middle);
	            // Below step sorts the right side of the array
	            doMergeSort(middle + 1, higherIndex);
	            // Now merge both sides
	            mergeParts(lowerIndex, middle, higherIndex);
	        }
	    }
	 
	    private void mergeParts(int lowerIndex, int middle, int higherIndex) {
	 
	        for (int i = lowerIndex; i <= higherIndex; i++) {
	            tempMergArr[i] = array[i];
	        }
	        int i = lowerIndex;
	        int j = middle + 1;
	        int k = lowerIndex;
	        while (i <= middle && j <= higherIndex) {
	            if (tempMergArr[i] <= tempMergArr[j]) {
	                array[k] = tempMergArr[i];
	                i++;
	            } else {
	                array[k] = tempMergArr[j];
	                j++;
	            }
	            k++;
	        }
	        while (i <= middle) {
	            array[k] = tempMergArr[i];
	            k++;
	            i++;
	        }
	 
	    }
}


 class  Count implements Comparable {
    	    Integer i;
    	    Integer j;
            Integer k;
    	    Count(int i,int j){
    	        this.i=i;
    	        this.j=j;
    	        this.k=0;
    	    }
    	    public Count() {
				// TODO Auto-generated constructor stub
			}
		
			void display(){
    	    	System.out.println(i+" "+j);
    	    }
    	    
    	    	@Override
    		public int compareTo(Object o) {
    			// TODO Auto-generated method stub
    			Count c=(Count)o;
    			if(i.compareTo(c.i)>0)
    				return 1;
    			else if(i.compareTo(c.i)<0)
    				return -1;
    			else{
    				return 0;
    				
    			}
    		}
				
    		
    	}

 class  Counti implements Comparable {
    	    Integer i;
    	    int j;
    	    int k;
    	    Counti(int i,int j,int k){
    	        this.j=j;
    	        this.i=i;
    	        this.k=k;
    	    }
    	    void display(){
    	    	System.out.println(i+" "+j);
    	    }
    	    
    	    	@Override
    		public int compareTo(Object o) {
    			// TODO Auto-generated method stub
    			Counti c=(Counti)o;
    			if(i.compareTo(c.i)>0)
    				return 1;
    			else if(i.compareTo(c.i)<0)
    	    		return -1;
    			else
    				return 0;
    		}
    	}
		
 class Extra{
	 ArrayList<Count> list=new ArrayList<>();
	 Extra(int i){
		 
	 }
	 public Extra() {
		// TODO Auto-generated constructor stub
	}
	void display(){
		 System.out.print(list.size()+" ");
		 for(int i=0;i<list.size();i++){
			 System.out.print(list.get(i)+" ");
		 }
		 System.out.println();
	 }
 }