#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize(2)
using namespace std;
const int maxn = 510;
const int inf32 = 1e9 + 10;
const long long inf64 = 1e18 + 10;
const int mod = 998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N;
  cin >> N;
  vector<long long> a(N), b(N);
  for (int i = 0; i < N; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  for (int i = 0; i < N; ++i) b[i] = a[N - 1] - a[i];
  vector<vector<long long>> dp(65, vector<long long>(N + 1, inf64));
  vector<vector<int>> sum(N + 1, vector<int>(2));
  dp[0][0] = 0;
  for (int i = 1; i <= 63; ++i) {
    int current_bit = i - 1;
    vector<int> p(N);
    for (int j = 0; j < N; ++j) p[j] = j;
    sort(p.begin(), p.end(), [&](int& l, int& r) {
      return b[l] % (1ll << current_bit) < b[r] % (1ll << current_bit);
    });
    for (int j = 0; j <= N; ++j) {
      for (int k = 0; k < 2; ++k) {
        sum[j][k] = 0;
      }
    }
    for (int j = 1; j <= N; ++j) {
      ++sum[j][b[p[j - 1]] >> current_bit & 1];
    }
    for (int j = 1; j <= N; ++j) {
      for (int k = 0; k < 2; ++k) {
        sum[j][k] += sum[j - 1][k];
      }
    }
    for (int j = 0; j <= N; ++j) {
      int new_carry = sum[N][1] - sum[N - j][1];
      int cost = sum[N - j][1] + sum[N][0] - sum[N - j][0];
      dp[i][new_carry] = min(dp[i][new_carry], dp[i - 1][j] + cost);
      new_carry =
          sum[N][1] - sum[N - j][1] + sum[N][0] - sum[N - j][0] + sum[N - j][1];
      cost = sum[N - j][0] + sum[N][1] - sum[N - j][1];
      dp[i][new_carry] = min(dp[i][new_carry], dp[i - 1][j] + cost);
    }
  }
  cout << dp[63][0] << endl;
}

### Prompt

In CPP, your task is to solve 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(3)
#pragma GCC optimize(2)
using namespace std;
const int maxn = 510;
const int inf32 = 1e9 + 10;
const long long inf64 = 1e18 + 10;
const int mod = 998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N;
  cin >> N;
  vector<long long> a(N), b(N);
  for (int i = 0; i < N; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  for (int i = 0; i < N; ++i) b[i] = a[N - 1] - a[i];
  vector<vector<long long>> dp(65, vector<long long>(N + 1, inf64));
  vector<vector<int>> sum(N + 1, vector<int>(2));
  dp[0][0] = 0;
  for (int i = 1; i <= 63; ++i) {
    int current_bit = i - 1;
    vector<int> p(N);
    for (int j = 0; j < N; ++j) p[j] = j;
    sort(p.begin(), p.end(), [&](int& l, int& r) {
      return b[l] % (1ll << current_bit) < b[r] % (1ll << current_bit);
    });
    for (int j = 0; j <= N; ++j) {
      for (int k = 0; k < 2; ++k) {
        sum[j][k] = 0;
      }
    }
    for (int j = 1; j <= N; ++j) {
      ++sum[j][b[p[j - 1]] >> current_bit & 1];
    }
    for (int j = 1; j <= N; ++j) {
      for (int k = 0; k < 2; ++k) {
        sum[j][k] += sum[j - 1][k];
      }
    }
    for (int j = 0; j <= N; ++j) {
      int new_carry = sum[N][1] - sum[N - j][1];
      int cost = sum[N - j][1] + sum[N][0] - sum[N - j][0];
      dp[i][new_carry] = min(dp[i][new_carry], dp[i - 1][j] + cost);
      new_carry =
          sum[N][1] - sum[N - j][1] + sum[N][0] - sum[N - j][0] + sum[N - j][1];
      cost = sum[N - j][0] + sum[N][1] - sum[N - j][1];
      dp[i][new_carry] = min(dp[i][new_carry], dp[i - 1][j] + cost);
    }
  }
  cout << dp[63][0] << endl;
}

```