#include <bits/stdc++.h>
using namespace std;
int n, K;
const int B = 60;
long long a[100005], maxi;
int f[64][100005], sum1[100005], sum0[100005];
long long read() {
  char c = getchar();
  long long x = 0;
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x;
}
bool comp(long long a, long long b) { return a % (1ll << K) < b % (1ll << K); }
void csort(int k) {
  K = k + 1;
  sort(a + 1, a + n + 1, comp);
}
void init(int k) {
  for (int i = 1; i <= n; ++i) {
    sum0[i] = sum0[i - 1] + !(a[i] >> k & 1);
    sum1[i] = sum1[i - 1] + (a[i] >> k & 1);
  }
}
int main() {
  n = (int)read();
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
    maxi = max(maxi, a[i]);
  }
  for (int i = 1; i <= n; ++i) a[i] = maxi - a[i];
  memset(f, 0x3f, sizeof(f));
  f[0][0] = 0;
  for (int i = 0; i < B; ++i) {
    if (i != 0) csort(i - 1);
    init(i);
    for (int j = 0; j <= n; ++j) {
      int l = sum1[n] - sum1[n - j], v = sum1[n - j] + sum0[n] - sum0[n - j];
      f[i + 1][l] = min(f[i + 1][l], f[i][j] + v);
      l = n - sum0[n - j];
      v = sum0[n - j] + sum1[n] - sum1[n - j];
      f[i + 1][l] = min(f[i + 1][l], f[i][j] + v);
    }
  }
  printf("%d\n", f[B][0]);
}

### Prompt

Please provide a CPP coded solution 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;
int n, K;
const int B = 60;
long long a[100005], maxi;
int f[64][100005], sum1[100005], sum0[100005];
long long read() {
  char c = getchar();
  long long x = 0;
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x;
}
bool comp(long long a, long long b) { return a % (1ll << K) < b % (1ll << K); }
void csort(int k) {
  K = k + 1;
  sort(a + 1, a + n + 1, comp);
}
void init(int k) {
  for (int i = 1; i <= n; ++i) {
    sum0[i] = sum0[i - 1] + !(a[i] >> k & 1);
    sum1[i] = sum1[i - 1] + (a[i] >> k & 1);
  }
}
int main() {
  n = (int)read();
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
    maxi = max(maxi, a[i]);
  }
  for (int i = 1; i <= n; ++i) a[i] = maxi - a[i];
  memset(f, 0x3f, sizeof(f));
  f[0][0] = 0;
  for (int i = 0; i < B; ++i) {
    if (i != 0) csort(i - 1);
    init(i);
    for (int j = 0; j <= n; ++j) {
      int l = sum1[n] - sum1[n - j], v = sum1[n - j] + sum0[n] - sum0[n - j];
      f[i + 1][l] = min(f[i + 1][l], f[i][j] + v);
      l = n - sum0[n - j];
      v = sum0[n - j] + sum1[n] - sum1[n - j];
      f[i + 1][l] = min(f[i + 1][l], f[i][j] + v);
    }
  }
  printf("%d\n", f[B][0]);
}

```