#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, K = 60;
long long a[N], b[K][N];
int f[K][N];
int n;
inline int getsum(int k, long long x) {
  long long w = 1ll << (k - 1);
  if (x < w)
    return upper_bound(b[k], b[k] + n, x + w) - upper_bound(b[k], b[k] + n, x);
  else
    return (upper_bound(b[k], b[k] + n, x - w) - b[k]) +
           (b[k] + n - upper_bound(b[k], b[k] + n, x));
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  for (int k = 1; k < K; ++k) {
    long long U = (1ll << k) - 1;
    for (int i = 0; i < n; i++) {
      b[k][i] = a[i] & U;
    }
    sort(b[k], b[k] + n);
  }
  for (int k = 0; k < K; k++)
    for (int i = 0; i <= n; i++) f[k][i] = 0x3f3f3f3f;
  f[0][n] = 0;
  for (int k = 1; k < K; k++) {
    for (int i = 0; i <= n; i++) {
      if (f[k - 1][i] == 0x3f3f3f3f) continue;
      if (i == 0 && b[k - 1][i] == 0) continue;
      for (long long bit = 0; bit < 2; bit++) {
        long long x = (i == 0 ? 0 : b[k - 1][i - 1]) + (bit << (k - 1));
        int pos = upper_bound(b[k], b[k] + n, x) - b[k];
        f[k][pos] = min(f[k][pos], f[k - 1][i] + getsum(k, x));
      }
    }
  }
  cout << f[K - 1][n] << endl;
}

### Prompt

In Cpp, your task is to solve the following problem:

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 N = 1e5 + 10, K = 60;
long long a[N], b[K][N];
int f[K][N];
int n;
inline int getsum(int k, long long x) {
  long long w = 1ll << (k - 1);
  if (x < w)
    return upper_bound(b[k], b[k] + n, x + w) - upper_bound(b[k], b[k] + n, x);
  else
    return (upper_bound(b[k], b[k] + n, x - w) - b[k]) +
           (b[k] + n - upper_bound(b[k], b[k] + n, x));
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  for (int k = 1; k < K; ++k) {
    long long U = (1ll << k) - 1;
    for (int i = 0; i < n; i++) {
      b[k][i] = a[i] & U;
    }
    sort(b[k], b[k] + n);
  }
  for (int k = 0; k < K; k++)
    for (int i = 0; i <= n; i++) f[k][i] = 0x3f3f3f3f;
  f[0][n] = 0;
  for (int k = 1; k < K; k++) {
    for (int i = 0; i <= n; i++) {
      if (f[k - 1][i] == 0x3f3f3f3f) continue;
      if (i == 0 && b[k - 1][i] == 0) continue;
      for (long long bit = 0; bit < 2; bit++) {
        long long x = (i == 0 ? 0 : b[k - 1][i - 1]) + (bit << (k - 1));
        int pos = upper_bound(b[k], b[k] + n, x) - b[k];
        f[k][pos] = min(f[k][pos], f[k - 1][i] + getsum(k, x));
      }
    }
  }
  cout << f[K - 1][n] << endl;
}

```