#include <bits/stdc++.h>
using namespace std;
const int max_n = 100011, inf = 1000111222;
const int max_bit = 64;
int n, dp[2][max_n];
long long a[2][max_n];
int q1 = 0, q2 = 1;
bool get_bit(long long x, int pos) { return (x >> pos) & 1; }
void upd(int q, int i, int cnt) {
  i = n - i;
  dp[q][i] = min(dp[q][i], cnt);
}
int main() {
  scanf("%d", &n);
  long long mx = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%I64d", &a[q1][i]);
    mx = max(mx, a[q1][i]);
    dp[q1][i] = inf;
  }
  for (int i = 0; i < n; ++i) {
    a[q1][i] = mx - a[q1][i];
  }
  for (int b = 0; b < max_bit; ++b) {
    for (int i = 0; i <= n; ++i) {
      dp[q2][i] = inf;
    }
    int c01 = 0, c11 = 0;
    for (int i = 0; i < n; ++i) {
      c11 += get_bit(a[q1][i], b);
    }
    for (int i = 0; i <= n; ++i) {
      const int c00 = i - c01;
      const int c10 = n - i - c11;
      upd(q2, c11, dp[q1][i] + c01 + c10);
      upd(q2, c11 + c10 + c01, dp[q1][i] + c00 + c11);
      c01 += get_bit(a[q1][i], b);
      c11 -= get_bit(a[q1][i], b);
    }
    int pos = 0;
    for (int i = 0; i < n; ++i) {
      if (!get_bit(a[q1][i], b)) {
        a[q2][pos++] = a[q1][i];
      }
    }
    for (int i = 0; i < n; ++i) {
      if (get_bit(a[q1][i], b)) {
        a[q2][pos++] = a[q1][i];
      }
    }
    swap(q1, q2);
  }
  printf("%d\n", dp[q1][n]);
  return 0;
}

### Prompt

Develop a solution in CPP to the problem described below:

You are given n numbers a_1, a_2, ..., a_n. In one operation we can add to any one of those numbers a nonnegative integer power of 2.

What is the smallest number of operations we need to perform to make all n numbers equal? It can be proved that under given constraints it doesn't exceed 10^{18}.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5).

The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^{17}).

Output

Output exactly one integer — the smallest number of operations we need to perform to make all n numbers equal.

Examples

Input


4
228 228 228 228


Output


0

Input


3
2 2 8


Output


3

Note

In the first example, all numbers are already equal. So the needed number of operation is 0.

In the second example, we can apply the operation 3 times: add 8 to first 2, add 8 to second 2, add 2 to 8, making all numbers equal to 10. It can be proved that we can't make all numbers equal in less than 3 operations.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int max_n = 100011, inf = 1000111222;
const int max_bit = 64;
int n, dp[2][max_n];
long long a[2][max_n];
int q1 = 0, q2 = 1;
bool get_bit(long long x, int pos) { return (x >> pos) & 1; }
void upd(int q, int i, int cnt) {
  i = n - i;
  dp[q][i] = min(dp[q][i], cnt);
}
int main() {
  scanf("%d", &n);
  long long mx = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%I64d", &a[q1][i]);
    mx = max(mx, a[q1][i]);
    dp[q1][i] = inf;
  }
  for (int i = 0; i < n; ++i) {
    a[q1][i] = mx - a[q1][i];
  }
  for (int b = 0; b < max_bit; ++b) {
    for (int i = 0; i <= n; ++i) {
      dp[q2][i] = inf;
    }
    int c01 = 0, c11 = 0;
    for (int i = 0; i < n; ++i) {
      c11 += get_bit(a[q1][i], b);
    }
    for (int i = 0; i <= n; ++i) {
      const int c00 = i - c01;
      const int c10 = n - i - c11;
      upd(q2, c11, dp[q1][i] + c01 + c10);
      upd(q2, c11 + c10 + c01, dp[q1][i] + c00 + c11);
      c01 += get_bit(a[q1][i], b);
      c11 -= get_bit(a[q1][i], b);
    }
    int pos = 0;
    for (int i = 0; i < n; ++i) {
      if (!get_bit(a[q1][i], b)) {
        a[q2][pos++] = a[q1][i];
      }
    }
    for (int i = 0; i < n; ++i) {
      if (get_bit(a[q1][i], b)) {
        a[q2][pos++] = a[q1][i];
      }
    }
    swap(q1, q2);
  }
  printf("%d\n", dp[q1][n]);
  return 0;
}

```