#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
long long arr[MAXN], srt[MAXN];
int f[2][MAXN], n;
void upd(int &a, int b) { a = a > b ? b : a; }
int main() {
  scanf("%d", &n);
  long long mx = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", arr + i);
    mx = max(mx, arr[i]);
  }
  for (int i = 1; i <= n; i++) arr[i] = mx - arr[i];
  mx = 0;
  for (int i = 1; i <= n; i++) mx = max(arr[i], mx);
  memset(f[0], 0x3f, sizeof(f[0]));
  f[0][0] = 0;
  int fin = 0;
  for (int i = 0; 1LL << i <= mx; i++) {
    int sp = 0, c1 = 0, now = i & 1, nxt = !now;
    memset(f[nxt], 0x3f, sizeof(f[nxt]));
    for (int j = 1; j <= n; j++) c1 += arr[j] >> i & 1;
    for (int j = 0; j <= n; j++) {
      sp += arr[j] >> i & 1;
      if (f[now][j] < 1E9) {
        upd(f[nxt][sp], f[now][j] + j - sp + c1 - sp);
        upd(f[nxt][c1 + j - sp], f[now][j] + sp + n - j - (c1 - sp));
      }
    }
    c1 = 0;
    for (int j = 1; j <= n; j++)
      if (arr[j] >> i & 1)
        srt[++c1] = arr[j];
      else
        srt[++sp] = arr[j];
    for (int j = 1; j <= n; j++) arr[j] = srt[j];
    fin = nxt;
  }
  int res = 0x3f3f3f3f;
  for (int i = 0; i <= n; i++) res = min(res, f[fin][i] + i);
  printf("%d\n", res);
  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 MAXN = 100005;
long long arr[MAXN], srt[MAXN];
int f[2][MAXN], n;
void upd(int &a, int b) { a = a > b ? b : a; }
int main() {
  scanf("%d", &n);
  long long mx = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", arr + i);
    mx = max(mx, arr[i]);
  }
  for (int i = 1; i <= n; i++) arr[i] = mx - arr[i];
  mx = 0;
  for (int i = 1; i <= n; i++) mx = max(arr[i], mx);
  memset(f[0], 0x3f, sizeof(f[0]));
  f[0][0] = 0;
  int fin = 0;
  for (int i = 0; 1LL << i <= mx; i++) {
    int sp = 0, c1 = 0, now = i & 1, nxt = !now;
    memset(f[nxt], 0x3f, sizeof(f[nxt]));
    for (int j = 1; j <= n; j++) c1 += arr[j] >> i & 1;
    for (int j = 0; j <= n; j++) {
      sp += arr[j] >> i & 1;
      if (f[now][j] < 1E9) {
        upd(f[nxt][sp], f[now][j] + j - sp + c1 - sp);
        upd(f[nxt][c1 + j - sp], f[now][j] + sp + n - j - (c1 - sp));
      }
    }
    c1 = 0;
    for (int j = 1; j <= n; j++)
      if (arr[j] >> i & 1)
        srt[++c1] = arr[j];
      else
        srt[++sp] = arr[j];
    for (int j = 1; j <= n; j++) arr[j] = srt[j];
    fin = nxt;
  }
  int res = 0x3f3f3f3f;
  for (int i = 0; i <= n; i++) res = min(res, f[fin][i] + i);
  printf("%d\n", res);
  return 0;
}

```