#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1.01e9;
const long long infll = (long long)1.01e18;
const long double eps = 1e-9;
const long double pi = acos((long double)-1);
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
void precalc() {}
const int maxn = (int)1e5 + 5;
int n;
long long a[maxn];
bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  return true;
}
const int maxb = 60;
pair<long long, int> b[maxn], c[maxn];
int dp[maxn], ndp[maxn];
int cnt[maxn];
void solve() {
  for (int i = 0; i < n; i++) {
    dp[i] = i;
  }
  dp[n] = 0;
  for (int i = 0; i < n; i++) {
    c[i] = make_pair(a[i], i);
  }
  sort(c, c + n);
  for (int bit = maxb - 1; bit >= 0; bit--) {
    for (int i = 0; i < n; i++) {
      b[i] = make_pair((a[i] & ((1ll << bit) - 1)), i);
    }
    sort(b, b + n);
    cnt[0] = 0;
    for (int i = 0; i < n; i++) {
      int id = b[i].second;
      cnt[i + 1] = cnt[i] + ((a[id] >> bit) & 1);
    }
    b[n].first = (1ll << bit);
    for (int i = 0; i <= n; i++) {
      int x = cnt[i] + ((n - i) - (cnt[n] - cnt[i]));
      int j = lower_bound(c, c + n, make_pair(b[i].first, -1)) - c;
      ndp[i] = dp[j] + x;
      j = lower_bound(c, c + n, make_pair(b[i].first + (1ll << bit), -1)) - c;
      ndp[i] = min(ndp[i], dp[j] + n - x);
    }
    swap(b, c);
    swap(dp, ndp);
  }
  printf("%d\n", dp[n]);
}
int main() {
  precalc();
  while (read()) {
    solve();
  }
  return 0;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

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 inf = (int)1.01e9;
const long long infll = (long long)1.01e18;
const long double eps = 1e-9;
const long double pi = acos((long double)-1);
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
void precalc() {}
const int maxn = (int)1e5 + 5;
int n;
long long a[maxn];
bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  return true;
}
const int maxb = 60;
pair<long long, int> b[maxn], c[maxn];
int dp[maxn], ndp[maxn];
int cnt[maxn];
void solve() {
  for (int i = 0; i < n; i++) {
    dp[i] = i;
  }
  dp[n] = 0;
  for (int i = 0; i < n; i++) {
    c[i] = make_pair(a[i], i);
  }
  sort(c, c + n);
  for (int bit = maxb - 1; bit >= 0; bit--) {
    for (int i = 0; i < n; i++) {
      b[i] = make_pair((a[i] & ((1ll << bit) - 1)), i);
    }
    sort(b, b + n);
    cnt[0] = 0;
    for (int i = 0; i < n; i++) {
      int id = b[i].second;
      cnt[i + 1] = cnt[i] + ((a[id] >> bit) & 1);
    }
    b[n].first = (1ll << bit);
    for (int i = 0; i <= n; i++) {
      int x = cnt[i] + ((n - i) - (cnt[n] - cnt[i]));
      int j = lower_bound(c, c + n, make_pair(b[i].first, -1)) - c;
      ndp[i] = dp[j] + x;
      j = lower_bound(c, c + n, make_pair(b[i].first + (1ll << bit), -1)) - c;
      ndp[i] = min(ndp[i], dp[j] + n - x);
    }
    swap(b, c);
    swap(dp, ndp);
  }
  printf("%d\n", dp[n]);
}
int main() {
  precalc();
  while (read()) {
    solve();
  }
  return 0;
}

```