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.
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author meashish
 */

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.Stack;

public class Main {

    private void start(InputReader in, PrintStream out) {
        int n = in.nextInt();
        
        int a[] = new int[n];
        
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        
        Arrays.sort(a);
        
        int first[] = new int[n];
        for (int i = 0; i < n; i++) {
            first[i] = 31 - Integer.numberOfLeadingZeros(a[i]);
        }
        
        int havedone = 0;
        for (int i = 0; i <= first[0]; i++) {
            int firstdig = a[0] & (1 << (first[0] - i));
            if (firstdig != 0) {
                firstdig = 1;
            }
            
            boolean bool = true;
            
            for (int j = 1; j < n; j++) {
                int firstdig2 = a[j] & (1 << (first[j] - i));
                
                if (firstdig2 != 0) {
                    firstdig2 = 1;
                }
                
                if (firstdig2 != firstdig) {
                    bool = false;
                }
            }
            
            if (bool) {
                havedone++;
            } else {
                break;
            }
        }
        
        int arr[] = new int[n];
        
        int anss = 0;
        for (int i = 0; i < n; i++) {
            int tmp = 0;
            for (int j = first[i] - havedone; j >= 0; j--) {
                if ((a[i] & (1 << j)) == 0) {
                    tmp++;
                } else {
                    break;
                }
            }
            
            anss += first[i] - havedone - tmp + 1;
            arr[i] = tmp;    
            //System.out.println("arri " + (first[i] - havedone - tmp + 1));
        }
        
        Arrays.sort(arr);
        
        if (n % 2 == 1) {
            int mid = arr[n / 2];
            
            int ans = 0;
            for (int i = 0; i < n / 2; i++) {
                ans += mid - arr[i];
            }
            for (int i = n / 2 + 1; i < n; i++) {
                ans += arr[i] - mid;
            }
            
            System.out.println((ans + anss));
        } else {
            int mid1 = arr[n / 2];
            
            int ans1 = 0;
            for (int i = 0; i < n / 2; i++) {
                ans1 += mid1 - arr[i];
            }
            for (int i = n / 2 + 1; i < n; i++) {
                ans1 += arr[i] - mid1;
            }
            
            int mid2 = arr[n / 2 - 1];
            
            int ans2 = 0;
            for (int i = 0; i < n / 2 - 1; i++) {
                ans2 += mid2 - arr[i];
            }
            for (int i = n / 2; i < n; i++) {
                ans2 += arr[i] - mid2;
            }
            
            System.out.println((Math.min(ans1, ans2) + anss));
        }
    }

    public static void main(String[] args) throws Exception {
        //InputReader in = new InputReader(new FileInputStream(new File("in.txt")));
        //PrintStream out = new PrintStream("out.txt");

        InputReader in = new InputReader(System.in);
        PrintStream out = System.out;

        new Main().start(in, out);
    }

    private static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {

            public boolean isSpaceChar(int ch);
        }
    }

    private class Pair<K, V> implements Serializable {

        private K key;

        public K getKey() {
            return key;
        }
        private V value;

        public V getValue() {
            return value;
        }

        public Pair(K key, V value) {
            this.key = key;
            this.value = value;
        }

        @Override
        public String toString() {
            return key + "=" + value;
        }

        @Override
        public int hashCode() {
            return key.hashCode() * 13 + (value == null ? 0 : value.hashCode());
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o instanceof Pair) {
                Pair pair = (Pair) o;
                if (key != null ? !key.equals(pair.key) : pair.key != null) {
                    return false;
                }
                if (value != null ? !value.equals(pair.value) : pair.value != null) {
                    return false;
                }
                return true;
            }
            return false;
        }
    }

}