#include <bits/stdc++.h>
clock_t t = clock();
namespace my_std {
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
inline T rnd(T l, T r) {
  return uniform_int_distribution<T>(l, r)(rng);
}
template <typename T>
inline bool chkmax(T& x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmin(T& x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T& t) {
  t = 0;
  char f = 0, ch = getchar();
  double d = 0.1;
  while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
  while (ch <= '9' && ch >= '0') t = t * 10 + ch - 48, ch = getchar();
  if (ch == '.') {
    ch = getchar();
    while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar();
  }
  t = (f ? -t : t);
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
char __sr[1 << 21], __z[20];
int __C = -1, __zz = 0;
inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; }
inline void print(register int x) {
  if (__C > 1 << 20) Ot();
  if (x < 0) __sr[++__C] = '-', x = -x;
  while (__z[++__zz] = x % 10 + 48, x /= 10)
    ;
  while (__sr[++__C] = __z[__zz], --__zz)
    ;
  __sr[++__C] = '\n';
}
void file() {}
inline void chktime() {}
long long ksm(long long x, int y) {
  long long ret = 1;
  for (; y; y >>= 1, x = x * x)
    if (y & 1) ret = ret * x;
  return ret;
}
}  // namespace my_std
using namespace my_std;
int n;
long long a[101001], b[101001];
int K;
bool cmp(long long x, long long y) {
  return (x & ((1ll << K) - 1)) < (y & ((1ll << K) - 1));
}
int sum[63][2][101001];
int dp[63][101001];
int main() {
  file();
  read(n);
  for (int i = (1); i <= (n); i++) read(a[i]);
  for (int k = (0); k <= (61); k++) {
    for (int i = (1); i <= (n); i++) b[i] = a[i];
    K = k;
    sort(b + 1, b + n + 1, cmp);
    for (int i = (1); i <= (n); i++) sum[k][b[i] >> k & 1][i]++;
    for (int j = (0); j <= (1); j++)
      for (int i = (1); i <= (n); i++) sum[k][j][i] += sum[k][j][i - 1];
  }
  memset(dp, 0x3f, sizeof(dp));
  dp[0][n] = 0;
  for (int k = (0); k <= (60); k++)
    for (int i = (0); i <= (n); i++) {
      int w = dp[k][i];
      if (w > 1e7) continue;
      int a = sum[k][0][i], b = sum[k][1][i], c = sum[k][0][n] - a,
          d = n - a - b - c;
      chkmin(dp[k + 1][a], w + b + c);
      chkmin(dp[k + 1][a + b + c], w + a + d);
    }
  cout << dp[61][n];
  return 0;
}

### Prompt

Develop a solution in CPP 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>
clock_t t = clock();
namespace my_std {
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
inline T rnd(T l, T r) {
  return uniform_int_distribution<T>(l, r)(rng);
}
template <typename T>
inline bool chkmax(T& x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmin(T& x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T& t) {
  t = 0;
  char f = 0, ch = getchar();
  double d = 0.1;
  while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
  while (ch <= '9' && ch >= '0') t = t * 10 + ch - 48, ch = getchar();
  if (ch == '.') {
    ch = getchar();
    while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar();
  }
  t = (f ? -t : t);
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
char __sr[1 << 21], __z[20];
int __C = -1, __zz = 0;
inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; }
inline void print(register int x) {
  if (__C > 1 << 20) Ot();
  if (x < 0) __sr[++__C] = '-', x = -x;
  while (__z[++__zz] = x % 10 + 48, x /= 10)
    ;
  while (__sr[++__C] = __z[__zz], --__zz)
    ;
  __sr[++__C] = '\n';
}
void file() {}
inline void chktime() {}
long long ksm(long long x, int y) {
  long long ret = 1;
  for (; y; y >>= 1, x = x * x)
    if (y & 1) ret = ret * x;
  return ret;
}
}  // namespace my_std
using namespace my_std;
int n;
long long a[101001], b[101001];
int K;
bool cmp(long long x, long long y) {
  return (x & ((1ll << K) - 1)) < (y & ((1ll << K) - 1));
}
int sum[63][2][101001];
int dp[63][101001];
int main() {
  file();
  read(n);
  for (int i = (1); i <= (n); i++) read(a[i]);
  for (int k = (0); k <= (61); k++) {
    for (int i = (1); i <= (n); i++) b[i] = a[i];
    K = k;
    sort(b + 1, b + n + 1, cmp);
    for (int i = (1); i <= (n); i++) sum[k][b[i] >> k & 1][i]++;
    for (int j = (0); j <= (1); j++)
      for (int i = (1); i <= (n); i++) sum[k][j][i] += sum[k][j][i - 1];
  }
  memset(dp, 0x3f, sizeof(dp));
  dp[0][n] = 0;
  for (int k = (0); k <= (60); k++)
    for (int i = (0); i <= (n); i++) {
      int w = dp[k][i];
      if (w > 1e7) continue;
      int a = sum[k][0][i], b = sum[k][1][i], c = sum[k][0][n] - a,
          d = n - a - b - c;
      chkmin(dp[k + 1][a], w + b + c);
      chkmin(dp[k + 1][a + b + c], w + a + d);
    }
  cout << dp[61][n];
  return 0;
}

```