#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, LG = 60 + 4;
int n, rnk[LG][N], dp[LG][N];
long long a[N];
inline void sparce_rank() {
  iota(rnk[0], rnk[0] + n, 0);
  for (int i = 0; i < LG - 1; i++) {
    copy(rnk[i], rnk[i] + n, rnk[i + 1]);
    stable_sort(rnk[i + 1], rnk[i + 1] + n, [i](int u, int v) {
      return (a[u] >> i & 1) > (a[v] >> i & 1);
    });
  }
}
inline void fill_sparce_dp() {
  for (int i = 1; i < n; i++) dp[LG - 1][i] = n - i;
  for (int i = LG - 2; ~i; i--) {
    int zero = 0, one = 0, two = 0;
    for (int j = 0; j < n; j++) {
      zero += ~a[j] >> i & 1;
      one += a[j] >> i & 1;
    }
    for (int j = 0; j <= n; j++) {
      dp[i][j] = min(dp[i + 1][two] + zero, dp[i + 1][one + two] + one);
      int b = a[rnk[i][j]] >> i & 1;
      zero += b - !b;
      one += !b - b;
      two += b;
    }
  }
}
inline void read_input() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
}
inline void solve() {
  sparce_rank();
  fill_sparce_dp();
  cout << dp[0][0];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read_input(), solve();
  return 0;
}

### Prompt

Please provide a Cpp coded solution 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;
const int N = 1e5 + 5, LG = 60 + 4;
int n, rnk[LG][N], dp[LG][N];
long long a[N];
inline void sparce_rank() {
  iota(rnk[0], rnk[0] + n, 0);
  for (int i = 0; i < LG - 1; i++) {
    copy(rnk[i], rnk[i] + n, rnk[i + 1]);
    stable_sort(rnk[i + 1], rnk[i + 1] + n, [i](int u, int v) {
      return (a[u] >> i & 1) > (a[v] >> i & 1);
    });
  }
}
inline void fill_sparce_dp() {
  for (int i = 1; i < n; i++) dp[LG - 1][i] = n - i;
  for (int i = LG - 2; ~i; i--) {
    int zero = 0, one = 0, two = 0;
    for (int j = 0; j < n; j++) {
      zero += ~a[j] >> i & 1;
      one += a[j] >> i & 1;
    }
    for (int j = 0; j <= n; j++) {
      dp[i][j] = min(dp[i + 1][two] + zero, dp[i + 1][one + two] + one);
      int b = a[rnk[i][j]] >> i & 1;
      zero += b - !b;
      one += !b - b;
      two += b;
    }
  }
}
inline void read_input() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
}
inline void solve() {
  sparce_rank();
  fill_sparce_dp();
  cout << dp[0][0];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read_input(), solve();
  return 0;
}

```