#include <bits/stdc++.h>
using namespace std;
const int SZ = 1e6 + 10;
const int INF = 1e9 + 10;
const int mod = 998244353;
const long double eps = 1e-8;
long long read() {
  long long n = 0;
  char a = getchar();
  bool flag = 0;
  while (a > '9' || a < '0') {
    if (a == '-') flag = 1;
    a = getchar();
  }
  while (a <= '9' && a >= '0') {
    n = n * 10 + a - '0', a = getchar();
  }
  if (flag) n = -n;
  return n;
}
pair<long long, long long> a[SZ];
long long f[SZ], g[SZ];
long long get(long long x) {
  long long ans = 0;
  while (x) ans += x & 1, x >>= 1;
  return ans;
}
void print(long long x) {
  for (int i = 63; i >= 0; i--) {
    if (x >> i & 1)
      printf("%d", x >> i & 1);
    else
      printf(" ");
  }
  printf("|");
}
long long get_low(long long x, long long k) { return x % (1ll << k); }
int k;
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  long long msk = 1ll << k;
  msk--;
  long long x = a.first & msk;
  long long y = b.first & msk;
  return x == y ? a.second < b.second : x > y;
}
int main() {
  int n = read();
  long long maxn = 0;
  for (int i = 1; i <= n; i++)
    a[i].first = read(), maxn = max(maxn, a[i].first);
  for (int i = 1; i <= n; i++) a[i].first = maxn - a[i].first, a[i].second = i;
  for (int i = 1; i <= n; i++) f[i] = 1e18;
  for (k = 0; k < 63; k++) {
    sort(a + 1, a + 1 + n, cmp);
    int oneall = 0, one = 0, zero = 0;
    for (int i = 1; i <= n; i++) oneall += a[i].first >> k & 1;
    for (int i = 0; i <= n; i++) g[i] = 1e18;
    for (int i = 1; i <= n; i++) {
      if (a[i].first >> k & 1)
        one++;
      else
        zero++;
      g[one] = min(g[one], f[i] + oneall - one + zero);
      g[i + oneall - one] =
          min(g[i + oneall - one], f[i] + one + n - oneall - zero);
    }
    g[0] = min(g[0], f[0] + oneall);
    g[oneall] = min(g[oneall], f[0] + n - oneall);
    for (int i = 0; i <= n; i++) f[i] = g[i];
  }
  cout << f[0] << endl;
}

### Prompt

Generate a cpp solution to 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 SZ = 1e6 + 10;
const int INF = 1e9 + 10;
const int mod = 998244353;
const long double eps = 1e-8;
long long read() {
  long long n = 0;
  char a = getchar();
  bool flag = 0;
  while (a > '9' || a < '0') {
    if (a == '-') flag = 1;
    a = getchar();
  }
  while (a <= '9' && a >= '0') {
    n = n * 10 + a - '0', a = getchar();
  }
  if (flag) n = -n;
  return n;
}
pair<long long, long long> a[SZ];
long long f[SZ], g[SZ];
long long get(long long x) {
  long long ans = 0;
  while (x) ans += x & 1, x >>= 1;
  return ans;
}
void print(long long x) {
  for (int i = 63; i >= 0; i--) {
    if (x >> i & 1)
      printf("%d", x >> i & 1);
    else
      printf(" ");
  }
  printf("|");
}
long long get_low(long long x, long long k) { return x % (1ll << k); }
int k;
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  long long msk = 1ll << k;
  msk--;
  long long x = a.first & msk;
  long long y = b.first & msk;
  return x == y ? a.second < b.second : x > y;
}
int main() {
  int n = read();
  long long maxn = 0;
  for (int i = 1; i <= n; i++)
    a[i].first = read(), maxn = max(maxn, a[i].first);
  for (int i = 1; i <= n; i++) a[i].first = maxn - a[i].first, a[i].second = i;
  for (int i = 1; i <= n; i++) f[i] = 1e18;
  for (k = 0; k < 63; k++) {
    sort(a + 1, a + 1 + n, cmp);
    int oneall = 0, one = 0, zero = 0;
    for (int i = 1; i <= n; i++) oneall += a[i].first >> k & 1;
    for (int i = 0; i <= n; i++) g[i] = 1e18;
    for (int i = 1; i <= n; i++) {
      if (a[i].first >> k & 1)
        one++;
      else
        zero++;
      g[one] = min(g[one], f[i] + oneall - one + zero);
      g[i + oneall - one] =
          min(g[i + oneall - one], f[i] + one + n - oneall - zero);
    }
    g[0] = min(g[0], f[0] + oneall);
    g[oneall] = min(g[oneall], f[0] + n - oneall);
    for (int i = 0; i <= n; i++) f[i] = g[i];
  }
  cout << f[0] << endl;
}

```