#include <bits/stdc++.h>
template <class T>
inline void read(T &res) {
  res = 0;
  bool bo = 0;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    bo = 1;
  else
    res = c - 48;
  while ((c = getchar()) >= '0' && c <= '9')
    res = (res << 3) + (res << 1) + (c - 48);
  if (bo) res = ~res + 1;
}
template <class T>
inline T Min(const T &a, const T &b) {
  return a < b ? a : b;
}
template <class T>
inline T Max(const T &a, const T &b) {
  return a > b ? a : b;
}
const int N = 1e5 + 5, M = 64, INF = 0x3f3f3f3f;
int n, f[M][N], id[N], tmp0[N], tmp1[N];
long long a[N], mx;
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(a[i]), mx = Max(mx, a[i]);
  for (int i = 1; i <= n; i++) a[i] = mx - a[i];
  for (int T = 0; T <= 60; T++)
    for (int i = 0; i <= n; i++) f[T][i] = INF;
  f[0][0] = 0;
  for (int i = 1; i <= n; i++) id[i] = i;
  for (int T = 1; T <= 60; T++) {
    int t = T - 1, cnt0 = 0, cnt1 = 0, cnti = 0;
    for (int i = 1; i <= n; i++)
      if ((a[i] >> t) & 1)
        cnt1++;
      else
        cnt0++;
    for (int i = 0; i <= n; i++) {
      if (i) {
        ((a[id[i]] >> t) & 1 ? cnt1 : cnt0)--;
        ((a[id[i]] >> t) & 1 ? cnti : cnt1)++;
      }
      f[T][cnti] = Min(f[T][cnti], f[T - 1][i] + cnt1);
      f[T][cnt1 + cnti] = Min(f[T][cnt1 + cnti], f[T - 1][i] + cnt0 + cnti);
    }
    int tot0 = 0, tot1 = 0;
    for (int i = 1; i <= n; i++)
      if ((a[id[i]] >> t) & 1)
        tmp1[++tot1] = id[i];
      else
        tmp0[++tot0] = id[i];
    for (int i = 1; i <= tot1; i++) id[i] = tmp1[i];
    for (int i = 1; i <= tot0; i++) id[i + tot1] = tmp0[i];
  }
  return std::cout << f[60][0] << std::endl, 0;
}

### Prompt

Your challenge is to write 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>
template <class T>
inline void read(T &res) {
  res = 0;
  bool bo = 0;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    bo = 1;
  else
    res = c - 48;
  while ((c = getchar()) >= '0' && c <= '9')
    res = (res << 3) + (res << 1) + (c - 48);
  if (bo) res = ~res + 1;
}
template <class T>
inline T Min(const T &a, const T &b) {
  return a < b ? a : b;
}
template <class T>
inline T Max(const T &a, const T &b) {
  return a > b ? a : b;
}
const int N = 1e5 + 5, M = 64, INF = 0x3f3f3f3f;
int n, f[M][N], id[N], tmp0[N], tmp1[N];
long long a[N], mx;
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(a[i]), mx = Max(mx, a[i]);
  for (int i = 1; i <= n; i++) a[i] = mx - a[i];
  for (int T = 0; T <= 60; T++)
    for (int i = 0; i <= n; i++) f[T][i] = INF;
  f[0][0] = 0;
  for (int i = 1; i <= n; i++) id[i] = i;
  for (int T = 1; T <= 60; T++) {
    int t = T - 1, cnt0 = 0, cnt1 = 0, cnti = 0;
    for (int i = 1; i <= n; i++)
      if ((a[i] >> t) & 1)
        cnt1++;
      else
        cnt0++;
    for (int i = 0; i <= n; i++) {
      if (i) {
        ((a[id[i]] >> t) & 1 ? cnt1 : cnt0)--;
        ((a[id[i]] >> t) & 1 ? cnti : cnt1)++;
      }
      f[T][cnti] = Min(f[T][cnti], f[T - 1][i] + cnt1);
      f[T][cnt1 + cnti] = Min(f[T][cnt1 + cnti], f[T - 1][i] + cnt0 + cnti);
    }
    int tot0 = 0, tot1 = 0;
    for (int i = 1; i <= n; i++)
      if ((a[id[i]] >> t) & 1)
        tmp1[++tot1] = id[i];
      else
        tmp0[++tot0] = id[i];
    for (int i = 1; i <= tot1; i++) id[i] = tmp1[i];
    for (int i = 1; i <= tot0; i++) id[i + tot1] = tmp0[i];
  }
  return std::cout << f[60][0] << std::endl, 0;
}

```