#include <bits/stdc++.h>
using namespace std;
int n;
long long f[70][100010];
long long a[100010], Max, ans = 1e9;
inline long long read() {
  long long x = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return w ? -x : x;
}
void radix_sort(int bit) {
  vector<long long> v[2];
  v[0].clear();
  v[1].clear();
  for (int i = 1; i <= n; i++) v[a[i] >> bit & 1].emplace_back(a[i]);
  int pos = 0;
  for (int i = 1; i >= 0; i--)
    for (long long abc : v[i]) a[++pos] = abc;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) Max = max(Max, a[i] = read());
  for (int i = 1; i <= n; i++) a[i] = Max - a[i];
  memset(f, 0x3f, sizeof f);
  f[0][0] = 0;
  for (int i = 0; i < 62; i++) {
    if (i) radix_sort(i - 1);
    int cnt = 0, tot = 0;
    for (int j = 1; j <= n; j++)
      if (a[j] >> i & 1) cnt++;
    for (int j = 0; j <= n; j++) {
      if (a[j] >> i & 1) tot++;
      f[i + 1][cnt + (j - tot)] =
          min(f[i + 1][cnt + (j - tot)], f[i][j] + tot + (n - j) - (cnt - tot));
      f[i + 1][tot] = min(f[i + 1][tot], f[i][j] + j - tot * 2 + cnt);
    }
  }
  cout << f[62][0] << '\n';
}

### 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;
int n;
long long f[70][100010];
long long a[100010], Max, ans = 1e9;
inline long long read() {
  long long x = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return w ? -x : x;
}
void radix_sort(int bit) {
  vector<long long> v[2];
  v[0].clear();
  v[1].clear();
  for (int i = 1; i <= n; i++) v[a[i] >> bit & 1].emplace_back(a[i]);
  int pos = 0;
  for (int i = 1; i >= 0; i--)
    for (long long abc : v[i]) a[++pos] = abc;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) Max = max(Max, a[i] = read());
  for (int i = 1; i <= n; i++) a[i] = Max - a[i];
  memset(f, 0x3f, sizeof f);
  f[0][0] = 0;
  for (int i = 0; i < 62; i++) {
    if (i) radix_sort(i - 1);
    int cnt = 0, tot = 0;
    for (int j = 1; j <= n; j++)
      if (a[j] >> i & 1) cnt++;
    for (int j = 0; j <= n; j++) {
      if (a[j] >> i & 1) tot++;
      f[i + 1][cnt + (j - tot)] =
          min(f[i + 1][cnt + (j - tot)], f[i][j] + tot + (n - j) - (cnt - tot));
      f[i + 1][tot] = min(f[i + 1][tot], f[i][j] + j - tot * 2 + cnt);
    }
  }
  cout << f[62][0] << '\n';
}

```