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.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;

public class CF2_312C {
  
  static Reader sc = new Reader();
  static PrintWriter out = new PrintWriter(System.out);
  
  static int lowBit(int S) {
    int count = 0;
    while ((S & 1) == 0) {
      S >>= 1;
      count++;
    }
    return count;
  }
  
   
  
  public static void main(String[] args) throws IOException {
    int n = sc.nextInt();
    // Pair = trimmed number, real number
    PriorityQueue<Pair<Integer, Integer>> nums = new PriorityQueue<Pair<Integer, Integer>>();
    
    long steps = 0;
    int min = 1000000;
    
    for (int i = 0; i < n; i++) {
      int num = sc.nextInt();
      int low1 = lowBit(num);
      int trimmed = num >> Math.max(0,low1);
      min = Math.min(min, trimmed);
      nums.add(new Pair(trimmed, num));
    }
    
    while (nums.peek().first != min) {
      int num = nums.poll().second;
      
      while ((num & 1) == 0) {
        num >>= 1;
        steps++;
      }
      num >>= 1;
      steps++;
      
      int low1 = lowBit(num);
      int trimmed = num >> Math.max(0,low1);
      min = Math.min(min, trimmed);
      nums.add(new Pair(trimmed, num));
    }
    
    int[] fixed = new int[n];
    
    for (int i = 0; i < n; i++) {
      fixed[i] = nums.poll().second;
    }
    
    Arrays.sort(fixed);
    
    int indMedian = lowBit(fixed[n/2]);
    
    for (int i = 0; i < n; i++) {
      steps += Math.abs(lowBit(fixed[i]) - indMedian); 
    }
    
    out.println(steps);
    out.close();
  }
  
  /**
   * @author Juan Martínez (https://www.linkedin.com/in/martinezgjuan)
   * @tested UVA_10765, UVA_10986, UVA_11367, UVA_315, CF2_303E
   */
  public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements
          Comparable<Pair<U, V>> {
    public final U first;
    public final V second;

    public Pair(U first, V second) {
      this.first = first;
      this.second = second;
    }

    public int compareTo(Pair<U, V> that) {
      int value = this.first.compareTo(that.first);
      if (value != 0)
        return -value;
      return this.second.compareTo(that.second);
    }

    @Override
    public boolean equals(Object other) {
      if (!(other instanceof Pair)) {
        return false;
      }
      Pair that = (Pair<U, V>) other;
      return this.first.equals(that.first) && this.second.equals(that.second);
    }

    @Override
    public int hashCode() {
      return 31 * (527 + first.hashCode()) + second.hashCode();
    }

    @Override
    public String toString() {
      return "(" + first + ", " + second + ")";
    }
  }

  static class Reader {
    boolean consume = false; final private int BUFFER_SIZE = 1 << 12;private byte[] buffer;private int bufferPointer, bytesRead;private boolean reachedEnd = false;public Reader() {buffer = new byte[BUFFER_SIZE];bufferPointer = 0;bytesRead = 0;}
    public boolean hasNext() {return !reachedEnd;} private void fillBuffer() throws IOException {bytesRead = System.in.read(buffer, bufferPointer = 0, BUFFER_SIZE);if (bytesRead == -1) {buffer[0] = -1;reachedEnd = true;}}
    private void consumeSpaces() throws IOException {while (read() <= ' ' && reachedEnd == false);bufferPointer--;} private byte read() throws IOException {if (bufferPointer == bytesRead) {fillBuffer();}return buffer[bufferPointer++];}
    public String next() throws IOException {StringBuilder sb = new StringBuilder();consumeSpaces();byte c = read();do {sb.append((char) c);} while ((c = read()) > ' ');if (consume) {consumeSpaces();};if (sb.length() == 0) {return null;}return sb.toString();}
    public String nextLine() throws IOException {StringBuilder sb = new StringBuilder();byte c;boolean read = false;while ((c = read()) != -1) {if (c == '\n') {read = true;break;}if (c >= ' ')sb.append((char) c);}if (!read) {return null;}return sb.toString();}
    public int nextInt() throws IOException {consumeSpaces();int ret = 0;      byte c = read();boolean neg = (c == '-');if (neg) {c = read();}do {ret = ret * 10 + c - '0';} while ((c = read()) >= '0' && c <= '9');if (consume) {consumeSpaces();}if (neg) {return -ret;}return ret;}
    public long nextLong() throws IOException {consumeSpaces();long ret = 0;byte c = read();boolean neg = (c == '-');if (neg) {c = read();}do {ret = ret * 10L + c - '0';} while ((c = read()) >= '0' && c <= '9');if (consume) {consumeSpaces();}if (neg) {return -ret;}return ret;}
    public double nextDouble() throws IOException {consumeSpaces();double ret = 0;double div = 1;byte c = read();boolean neg = (c == '-');if (neg) {c = read();}do {ret = ret * 10 + c - '0';} while ((c = read()) >= '0' && c <= '9');if (c == '.') {while ((c = read()) >= '0' && c <= '9') {ret += (c - '0') / (div *= 10);}}if (consume) {consumeSpaces();}if (neg) {return -ret;}return ret;}    public int[] nextIntArray(int n) throws IOException {int[] a = new int[n];for (int i = 0; i < n; i++) {a[i] = nextInt();}return a;}
    public int[][] nextIntMatrix(int n, int m) throws IOException {int[][] grid = new int[n][m];for (int i = 0; i < n; i++) {grid[i] = nextIntArray(m);}return grid;}
    public char[][] nextCharacterMatrix(int n) throws IOException {char[][] a = new char[n][];for (int i = 0; i < n; i++) {a[i] = next().toCharArray();}return a;}
    public void close() throws IOException {if (System.in == null) {return;} else {System.in.close();}}
  }
  
  static void print(int[] A) {for (int i = 0; i < A.length; i++) {if (i != 0) {out.print(' ');}out.print(A[i]);}out.println();}
  static <T> void print(Iterable<T> A) {int i = 0;for (T act : A) {if (i != 0) {out.print(' ');}out.print(act);i++;}out.println();}
  static void printPlus1(Iterable<Number> A) {int i = 0;for (Number act : A) {if (i != 0) {out.print(' ');}out.print(act.longValue() + 1L);i++;}out.println();  }
  static void debug(Object... o) {System.err.println(Arrays.deepToString(o));}
  
  /*
  long s = System.currentTimeMillis();
  debug(System.currentTimeMillis() - s + "ms");
   */
}
