#include <bits/stdc++.h>
using namespace std;
const int BUF_SIZE = (int)1e6 + 10;
struct fastIO {
  char buf[BUF_SIZE], buf1[BUF_SIZE];
  int cur, cur1;
  FILE *in, *out;
  fastIO() {
    cur = BUF_SIZE, in = stdin, out = stdout;
    cur1 = 0;
  }
  inline char getchar() {
    if (cur == BUF_SIZE) fread(buf, BUF_SIZE, 1, in), cur = 0;
    return *(buf + (cur++));
  }
  inline void putchar(char ch) {
    *(buf1 + (cur1++)) = ch;
    if (cur1 == BUF_SIZE) fwrite(buf1, BUF_SIZE, 1, out), cur1 = 0;
  }
  inline int flush() {
    if (cur1 > 0) fwrite(buf1, cur1, 1, out);
    return cur1 = 0;
  }
} IO;
long long read() {
  char ch = IO.getchar();
  long long x = 0, flag = 1;
  for (; !isdigit(ch); ch = IO.getchar())
    if (ch == '-') flag *= -1;
  for (; isdigit(ch); ch = IO.getchar()) x = x * 10 + ch - 48;
  return x * flag;
}
void write(long long x) {
  if (x < 0) IO.putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  IO.putchar(x % 10 + 48);
}
const int Maxn = 100009;
long long n, a[Maxn];
void init() {
  n = read();
  for (int i = (1), i_end_ = (n); i <= i_end_; ++i) a[i] = read();
}
int dp[79][Maxn];
long long tmp[Maxn], mx, ori[Maxn];
int cnt[Maxn][4];
void basicSort(int pos) {
  int cru = 0;
  for (int i = (1), i_end_ = (n); i <= i_end_; ++i)
    if ((a[ori[i]] >> (pos - 1)) & 1) tmp[++cru] = ori[i];
  for (int i = (1), i_end_ = (n); i <= i_end_; ++i)
    if (!((a[ori[i]] >> (pos - 1)) & 1)) tmp[++cru] = ori[i];
  assert(cru == n);
  for (int i = (1), i_end_ = (n); i <= i_end_; ++i) ori[i] = tmp[i];
}
void solve() {
  for (int i = (1), i_end_ = (n); i <= i_end_; ++i) mx = max(mx, a[i]);
  for (int i = (1), i_end_ = (n); i <= i_end_; ++i)
    a[i] = mx - a[i], ori[i] = i;
  memset((dp), (0x3f), sizeof(dp));
  dp[0][0] = 0;
  for (int i = (0), i_end_ = (62); i <= i_end_; ++i) {
    if (i) basicSort(i);
    int sum0 = 0, sum1 = 0;
    for (int j = (1), j_end_ = (n); j <= j_end_; ++j)
      sum1 += ((a[ori[j]] >> i) & 1), sum0 += !((a[ori[j]] >> i) & 1);
    for (int j = (1), j_end_ = (n); j <= j_end_; ++j) {
      cnt[j][0] = cnt[j - 1][0];
      cnt[j][2] = cnt[j - 1][2];
      cnt[j][0] += ((a[ori[j]] >> i) & 1);
      cnt[j][2] += !((a[ori[j]] >> i) & 1);
    }
    for (int j = (n), j_end_ = (1); j >= j_end_; --j) {
      cnt[j][1] = cnt[j + 1][1];
      cnt[j][3] = cnt[j + 1][3];
      cnt[j][1] += ((a[ori[j]] >> i) & 1);
      cnt[j][3] += !((a[ori[j]] >> i) & 1);
    }
    for (int j = (0), j_end_ = (n); j <= j_end_; ++j) {
      if (dp[i][j] == 0x3f3f3f3f) continue;
      dp[i + 1][cnt[j][0]] =
          min(dp[i + 1][cnt[j][0]], dp[i][j] + cnt[j][2] + cnt[j + 1][1]);
      dp[i + 1][j + cnt[j + 1][1]] = min(dp[i + 1][j + cnt[j + 1][1]],
                                         dp[i][j] + cnt[j][0] + cnt[j + 1][3]);
    }
  }
  cout << dp[63][0] << endl;
}
int main() {
  init();
  solve();
  return IO.flush();
}

### 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 BUF_SIZE = (int)1e6 + 10;
struct fastIO {
  char buf[BUF_SIZE], buf1[BUF_SIZE];
  int cur, cur1;
  FILE *in, *out;
  fastIO() {
    cur = BUF_SIZE, in = stdin, out = stdout;
    cur1 = 0;
  }
  inline char getchar() {
    if (cur == BUF_SIZE) fread(buf, BUF_SIZE, 1, in), cur = 0;
    return *(buf + (cur++));
  }
  inline void putchar(char ch) {
    *(buf1 + (cur1++)) = ch;
    if (cur1 == BUF_SIZE) fwrite(buf1, BUF_SIZE, 1, out), cur1 = 0;
  }
  inline int flush() {
    if (cur1 > 0) fwrite(buf1, cur1, 1, out);
    return cur1 = 0;
  }
} IO;
long long read() {
  char ch = IO.getchar();
  long long x = 0, flag = 1;
  for (; !isdigit(ch); ch = IO.getchar())
    if (ch == '-') flag *= -1;
  for (; isdigit(ch); ch = IO.getchar()) x = x * 10 + ch - 48;
  return x * flag;
}
void write(long long x) {
  if (x < 0) IO.putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  IO.putchar(x % 10 + 48);
}
const int Maxn = 100009;
long long n, a[Maxn];
void init() {
  n = read();
  for (int i = (1), i_end_ = (n); i <= i_end_; ++i) a[i] = read();
}
int dp[79][Maxn];
long long tmp[Maxn], mx, ori[Maxn];
int cnt[Maxn][4];
void basicSort(int pos) {
  int cru = 0;
  for (int i = (1), i_end_ = (n); i <= i_end_; ++i)
    if ((a[ori[i]] >> (pos - 1)) & 1) tmp[++cru] = ori[i];
  for (int i = (1), i_end_ = (n); i <= i_end_; ++i)
    if (!((a[ori[i]] >> (pos - 1)) & 1)) tmp[++cru] = ori[i];
  assert(cru == n);
  for (int i = (1), i_end_ = (n); i <= i_end_; ++i) ori[i] = tmp[i];
}
void solve() {
  for (int i = (1), i_end_ = (n); i <= i_end_; ++i) mx = max(mx, a[i]);
  for (int i = (1), i_end_ = (n); i <= i_end_; ++i)
    a[i] = mx - a[i], ori[i] = i;
  memset((dp), (0x3f), sizeof(dp));
  dp[0][0] = 0;
  for (int i = (0), i_end_ = (62); i <= i_end_; ++i) {
    if (i) basicSort(i);
    int sum0 = 0, sum1 = 0;
    for (int j = (1), j_end_ = (n); j <= j_end_; ++j)
      sum1 += ((a[ori[j]] >> i) & 1), sum0 += !((a[ori[j]] >> i) & 1);
    for (int j = (1), j_end_ = (n); j <= j_end_; ++j) {
      cnt[j][0] = cnt[j - 1][0];
      cnt[j][2] = cnt[j - 1][2];
      cnt[j][0] += ((a[ori[j]] >> i) & 1);
      cnt[j][2] += !((a[ori[j]] >> i) & 1);
    }
    for (int j = (n), j_end_ = (1); j >= j_end_; --j) {
      cnt[j][1] = cnt[j + 1][1];
      cnt[j][3] = cnt[j + 1][3];
      cnt[j][1] += ((a[ori[j]] >> i) & 1);
      cnt[j][3] += !((a[ori[j]] >> i) & 1);
    }
    for (int j = (0), j_end_ = (n); j <= j_end_; ++j) {
      if (dp[i][j] == 0x3f3f3f3f) continue;
      dp[i + 1][cnt[j][0]] =
          min(dp[i + 1][cnt[j][0]], dp[i][j] + cnt[j][2] + cnt[j + 1][1]);
      dp[i + 1][j + cnt[j + 1][1]] = min(dp[i + 1][j + cnt[j + 1][1]],
                                         dp[i][j] + cnt[j][0] + cnt[j + 1][3]);
    }
  }
  cout << dp[63][0] << endl;
}
int main() {
  init();
  solve();
  return IO.flush();
}

```