#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353, N = 110000, inf = 1e9;
int n, lim, f[2][N];
long long a[N], tmp[N];
inline int addMod(int a, int b) { return (a += b) >= mod ? a - mod : a; }
inline long long quickpow(long long base, long long pw) {
  long long ret = 1;
  while (pw) {
    if (pw & 1) ret = ret * base % mod;
    base = base * base % mod, pw >>= 1;
  }
  return ret;
}
template <class T>
inline void read(T &x) {
  x = 0;
  char ch = getchar(), w = 0;
  while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = w ? -x : x;
  return;
}
int main() {
  read(n);
  for (register int i = 1; i <= n; ++i) {
    read(a[i]);
    while (1ll << lim <= a[i]) ++lim;
  }
  int n0 = -1;
  for (register int i = 0; i <= n; ++i) {
    f[0][i] = inf;
    if (~a[i] & 1) tmp[++n0] = a[i];
  }
  f[0][n0] = n - n0, f[0][n] = min(f[0][n], n0);
  for (register int i = 1; i <= n; ++i) {
    if (a[i] & 1) tmp[++n0] = a[i];
    a[i] = tmp[i];
  }
  for (register int i = 0, w = 1; i < lim; ++i, w ^= 1) {
    n0 = -1;
    for (register int j = 0; j <= n; ++j) {
      f[w][j] = inf;
      if ((~a[j] >> i >> 1) & 1) tmp[++n0] = a[j];
    }
    for (register int j = 0, m0 = -1; j <= n; ++j) {
      m0 += (~a[j] >> i >> 1) & 1;
      f[w][m0] = min(f[w][m0], f[w ^ 1][j] + n0 + j - 2 * m0);
      f[w][n0 + j - m0] =
          min(f[w][n0 + j - m0], f[w ^ 1][j] + n - n0 - j + 2 * m0);
    }
    for (register int j = 1; j <= n; ++j) {
      if ((a[j] >> i >> 1) & 1) tmp[++n0] = a[j];
      a[j] = tmp[j];
    }
  }
  cout << f[lim & 1][n] << endl;
  return 0;
}

### Prompt

Generate 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 mod = 998244353, N = 110000, inf = 1e9;
int n, lim, f[2][N];
long long a[N], tmp[N];
inline int addMod(int a, int b) { return (a += b) >= mod ? a - mod : a; }
inline long long quickpow(long long base, long long pw) {
  long long ret = 1;
  while (pw) {
    if (pw & 1) ret = ret * base % mod;
    base = base * base % mod, pw >>= 1;
  }
  return ret;
}
template <class T>
inline void read(T &x) {
  x = 0;
  char ch = getchar(), w = 0;
  while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = w ? -x : x;
  return;
}
int main() {
  read(n);
  for (register int i = 1; i <= n; ++i) {
    read(a[i]);
    while (1ll << lim <= a[i]) ++lim;
  }
  int n0 = -1;
  for (register int i = 0; i <= n; ++i) {
    f[0][i] = inf;
    if (~a[i] & 1) tmp[++n0] = a[i];
  }
  f[0][n0] = n - n0, f[0][n] = min(f[0][n], n0);
  for (register int i = 1; i <= n; ++i) {
    if (a[i] & 1) tmp[++n0] = a[i];
    a[i] = tmp[i];
  }
  for (register int i = 0, w = 1; i < lim; ++i, w ^= 1) {
    n0 = -1;
    for (register int j = 0; j <= n; ++j) {
      f[w][j] = inf;
      if ((~a[j] >> i >> 1) & 1) tmp[++n0] = a[j];
    }
    for (register int j = 0, m0 = -1; j <= n; ++j) {
      m0 += (~a[j] >> i >> 1) & 1;
      f[w][m0] = min(f[w][m0], f[w ^ 1][j] + n0 + j - 2 * m0);
      f[w][n0 + j - m0] =
          min(f[w][n0 + j - m0], f[w ^ 1][j] + n - n0 - j + 2 * m0);
    }
    for (register int j = 1; j <= n; ++j) {
      if ((a[j] >> i >> 1) & 1) tmp[++n0] = a[j];
      a[j] = tmp[j];
    }
  }
  cout << f[lim & 1][n] << endl;
  return 0;
}

```