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.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.max;
import static java.lang.Long.min;

public class C {
    public static void main(String[] args) {
        FastScanner in;
        PrintWriter out;

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        final int n = in.nextInt();
        final int[] a = new int[n];
        int top = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            top = max(top, a[i]);
        }
        top++;

        final int[] count = new int[top + 1];
        final int[] last = new int[top + 1];
        Arrays.fill(last, -1);
        final long[] sum = new long[top + 1];
        final int[] dis = new int[n + 1];
        final int[] diff = new int[n + 1];


        for (int i = 0; i < n; i++) {
            int cnode = 0;
            dis[cnode] = a[i];
            diff[cnode] = 0;
            while (cnode >= 0) {
                int di = dis[cnode];
                int diiff = diff[cnode];
                cnode--;
                if (last[di] == i) continue;

                count[di]++;
                sum[di] += diiff;
                last[di] = i;

                final int ld = di / 2;
                if (ld > 0 && last[ld] != i) {
                    cnode++;
                    dis[cnode] = ld;
                    diff[cnode] = diiff + 1;
                }

                final int rd = di * 2;
                if (rd < top && last[rd] != i) {
                    cnode++;
                    dis[cnode] = rd;
                    diff[cnode] = diiff + 1;
                }
            }
        }

        long ans = Long.MAX_VALUE;
        for (int i = 1; i < top; i++) {
            if (count[i] >= n) {
                ans = min(ans, sum[i]);
            }
        }

        out.println(ans);
        out.close();
    }

    static class Node {
        int d;
        int diff;
        private int i;

        public Node(int d, int diff, int i) {
            this.d = d;
            this.diff = diff;
            this.i = i;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Node node = (Node) o;

            if (d != node.d) return false;
            if (diff != node.diff) return false;
            return i == node.i;

        }

        @Override
        public int hashCode() {
            int result = d;
            result = 31 * result + diff;
            result = 31 * result + i;
            return result;
        }
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}
