#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long MOD = 1e9 + 7;
const int M = 200;
long long dp[M + 2][100001];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),
      cout << fixed << setprecision(20);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    a[i] = a[n - 1] - a[i];
  }
  for (int i = 0; i < n; i++) {
    long long kl = 0;
    long long aa = a[i];
    while (aa) {
      dp[kl][i] = aa % 2;
      kl++;
      aa /= 2;
    }
  }
  long long cur = 1;
  for (int i = 0; i <= 60; i++) {
    cur *= 2;
  }
  cur /= 2;
  for (int i = M; i > -1; i--) {
    vector<pair<long long, long long> > b;
    for (int j = 0; j < n; j++) {
      b.push_back({a[j] % cur, j});
    }
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    long long a1 = 0, a2 = 0;
    for (int j = 0; j < n; j++) {
      a1 += dp[i][j];
      a2 += 1 - dp[i][j];
    }
    vector<long long> dp_(n + 1);
    dp_[0] = min(a1 + dp[i + 1][0], a2 + dp[i + 1][a1]);
    long long gv = 0;
    for (int j = 0; j < n; j++) {
      if (!dp[i][b[j].second]) {
        a1++;
        a2--;
        dp_[j + 1] = min(a1 + dp[i + 1][gv], a2 + dp[i + 1][a1 + gv]);
      } else {
        gv++;
        a1--;
        a2++;
        dp_[j + 1] = min(a1 + dp[i + 1][gv], a2 + dp[i + 1][a1 + gv]);
      }
    }
    for (int j = 0; j < n + 1; j++) {
      dp[i][j] = dp_[j];
    }
    if (i <= 60) cur /= 2;
  }
  cout << dp[0][0];
}

### Prompt

Create a solution in Cpp for 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>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long MOD = 1e9 + 7;
const int M = 200;
long long dp[M + 2][100001];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),
      cout << fixed << setprecision(20);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    a[i] = a[n - 1] - a[i];
  }
  for (int i = 0; i < n; i++) {
    long long kl = 0;
    long long aa = a[i];
    while (aa) {
      dp[kl][i] = aa % 2;
      kl++;
      aa /= 2;
    }
  }
  long long cur = 1;
  for (int i = 0; i <= 60; i++) {
    cur *= 2;
  }
  cur /= 2;
  for (int i = M; i > -1; i--) {
    vector<pair<long long, long long> > b;
    for (int j = 0; j < n; j++) {
      b.push_back({a[j] % cur, j});
    }
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    long long a1 = 0, a2 = 0;
    for (int j = 0; j < n; j++) {
      a1 += dp[i][j];
      a2 += 1 - dp[i][j];
    }
    vector<long long> dp_(n + 1);
    dp_[0] = min(a1 + dp[i + 1][0], a2 + dp[i + 1][a1]);
    long long gv = 0;
    for (int j = 0; j < n; j++) {
      if (!dp[i][b[j].second]) {
        a1++;
        a2--;
        dp_[j + 1] = min(a1 + dp[i + 1][gv], a2 + dp[i + 1][a1 + gv]);
      } else {
        gv++;
        a1--;
        a2++;
        dp_[j + 1] = min(a1 + dp[i + 1][gv], a2 + dp[i + 1][a1 + gv]);
      }
    }
    for (int j = 0; j < n + 1; j++) {
      dp[i][j] = dp_[j];
    }
    if (i <= 60) cur /= 2;
  }
  cout << dp[0][0];
}

```