#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MAXL = 57;
const int INF = 1e9;
long long a[MAXN];
int dp[MAXL + 5][MAXN];
int sp[MAXN];
int b;
bool cmp(long long x, long long y) {
  x &= ((1LL << b) - 1);
  y &= ((1LL << b) - 1);
  return x > y;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  for (int i = 1; i <= n; ++i) dp[0][i] = INF;
  for (b = 0; b < MAXL; ++b) {
    sort(a + 1, a + n + 1, cmp);
    int c = 0;
    for (int i = 1; i <= n; ++i) {
      if ((a[i] & (1LL << b)) == 0LL)
        sp[i] = 1;
      else
        sp[i] = 0;
      sp[i] += sp[i - 1];
    }
    for (int i = 0; i <= n; ++i) dp[b + 1][i] = INF;
    for (int i = 0; i <= n; ++i) {
      int j = n - (sp[n] - sp[i]);
      int nc = sp[i] + (n - i - (sp[n] - sp[i])) + dp[b][i];
      dp[b + 1][j] = min(dp[b + 1][j], nc);
      j = i - sp[i];
      nc = i - sp[i] + sp[n] - sp[i] + dp[b][i];
      dp[b + 1][j] = min(dp[b + 1][j], nc);
    }
  }
  printf("%d\n", min(dp[MAXL][0], dp[MAXL][n]));
  return 0;
}

### Prompt

Your task is to create 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 MAXN = 100005;
const int MAXL = 57;
const int INF = 1e9;
long long a[MAXN];
int dp[MAXL + 5][MAXN];
int sp[MAXN];
int b;
bool cmp(long long x, long long y) {
  x &= ((1LL << b) - 1);
  y &= ((1LL << b) - 1);
  return x > y;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  for (int i = 1; i <= n; ++i) dp[0][i] = INF;
  for (b = 0; b < MAXL; ++b) {
    sort(a + 1, a + n + 1, cmp);
    int c = 0;
    for (int i = 1; i <= n; ++i) {
      if ((a[i] & (1LL << b)) == 0LL)
        sp[i] = 1;
      else
        sp[i] = 0;
      sp[i] += sp[i - 1];
    }
    for (int i = 0; i <= n; ++i) dp[b + 1][i] = INF;
    for (int i = 0; i <= n; ++i) {
      int j = n - (sp[n] - sp[i]);
      int nc = sp[i] + (n - i - (sp[n] - sp[i])) + dp[b][i];
      dp[b + 1][j] = min(dp[b + 1][j], nc);
      j = i - sp[i];
      nc = i - sp[i] + sp[n] - sp[i] + dp[b][i];
      dp[b + 1][j] = min(dp[b + 1][j], nc);
    }
  }
  printf("%d\n", min(dp[MAXL][0], dp[MAXL][n]));
  return 0;
}

```