#include <bits/stdc++.h>
using namespace std;
namespace mine {
long long qread() {
  long long ans = 0, f = 1;
  char c = getchar();
  while (c < '0' or c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar();
  return ans * f;
}
void write(long long num) {
  if (num < 0) putchar('-'), num = -num;
  if (num >= 10) write(num / 10);
  putchar('0' + num % 10);
}
void write1(long long num) {
  write(num);
  putchar(' ');
}
void write2(long long num) {
  write(num);
  putchar('\n');
}
template <typename T>
void chmax(T &x, const T y) {
  x = (x > y ? x : y);
}
template <typename T>
void chmin(T &x, const T y) {
  x = (x < y ? x : y);
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
int mm(const int x) { return x >= MOD ? x - MOD : x; }
template <typename T>
void add(T &x, const int &y) {
  x = (x + y >= MOD ? x + y - MOD : x + y);
}
long long qpower(long long x, long long e, int mod = MOD) {
  long long ans = 1;
  if (e < 0) {
    puts("error");
    exit(666);
  }
  while (e) {
    if (e & 1) ans = ans * x % mod;
    x = x * x % mod;
    e >>= 1;
  }
  return ans;
}
long long invm(long long x) { return qpower(x, MOD - 2); }
const int N = 1e5 + 10;
vector<long long> lst, now[2];
int f[100][N];
void main() {
  int n = qread();
  for (int i = (1), I = (n); i <= I; i++) lst.push_back(qread());
  memset(f, 0x3f, sizeof f);
  f[0][n] = 0;
  for (int k = (0), I = (59); k <= I; k++) {
    now[0].clear();
    now[1].clear();
    for (auto num : lst) now[(num >> k) & 1].push_back(num);
    int to, ad;
    to = ((int)(now[0]).size()), ad = ((int)(now[1]).size());
    chmin(f[k + 1][to], f[k][n] + ad);
    for (int i = (n - 1), I = (0); i >= I; i--)
      to -= (lst[i] & (1ll << (k))) == 0,
          ad += ((lst[i] & (1ll << (k))) == 0) - ((lst[i] & (1ll << (k))) > 0),
          chmin(f[k + 1][to], f[k][i] + ad);
    to = n, ad = ((int)(now[0]).size());
    chmin(f[k + 1][to], f[k][n] + ad);
    for (int i = (n - 1), I = (0); i >= I; i--)
      to -= (lst[i] & (1ll << (k))) > 0,
          ad += ((lst[i] & (1ll << (k))) > 0) - ((lst[i] & (1ll << (k))) == 0),
          chmin(f[k + 1][to], f[k][i] + ad);
    lst.clear();
    for (auto num : now[0]) lst.push_back(num);
    for (auto num : now[1]) lst.push_back(num);
  }
  write(f[60][n]);
}
};  // namespace mine
signed main() {
  srand(time(0));
  mine::main();
}

### Prompt

In CPP, your task is to solve 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;
namespace mine {
long long qread() {
  long long ans = 0, f = 1;
  char c = getchar();
  while (c < '0' or c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar();
  return ans * f;
}
void write(long long num) {
  if (num < 0) putchar('-'), num = -num;
  if (num >= 10) write(num / 10);
  putchar('0' + num % 10);
}
void write1(long long num) {
  write(num);
  putchar(' ');
}
void write2(long long num) {
  write(num);
  putchar('\n');
}
template <typename T>
void chmax(T &x, const T y) {
  x = (x > y ? x : y);
}
template <typename T>
void chmin(T &x, const T y) {
  x = (x < y ? x : y);
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
int mm(const int x) { return x >= MOD ? x - MOD : x; }
template <typename T>
void add(T &x, const int &y) {
  x = (x + y >= MOD ? x + y - MOD : x + y);
}
long long qpower(long long x, long long e, int mod = MOD) {
  long long ans = 1;
  if (e < 0) {
    puts("error");
    exit(666);
  }
  while (e) {
    if (e & 1) ans = ans * x % mod;
    x = x * x % mod;
    e >>= 1;
  }
  return ans;
}
long long invm(long long x) { return qpower(x, MOD - 2); }
const int N = 1e5 + 10;
vector<long long> lst, now[2];
int f[100][N];
void main() {
  int n = qread();
  for (int i = (1), I = (n); i <= I; i++) lst.push_back(qread());
  memset(f, 0x3f, sizeof f);
  f[0][n] = 0;
  for (int k = (0), I = (59); k <= I; k++) {
    now[0].clear();
    now[1].clear();
    for (auto num : lst) now[(num >> k) & 1].push_back(num);
    int to, ad;
    to = ((int)(now[0]).size()), ad = ((int)(now[1]).size());
    chmin(f[k + 1][to], f[k][n] + ad);
    for (int i = (n - 1), I = (0); i >= I; i--)
      to -= (lst[i] & (1ll << (k))) == 0,
          ad += ((lst[i] & (1ll << (k))) == 0) - ((lst[i] & (1ll << (k))) > 0),
          chmin(f[k + 1][to], f[k][i] + ad);
    to = n, ad = ((int)(now[0]).size());
    chmin(f[k + 1][to], f[k][n] + ad);
    for (int i = (n - 1), I = (0); i >= I; i--)
      to -= (lst[i] & (1ll << (k))) > 0,
          ad += ((lst[i] & (1ll << (k))) > 0) - ((lst[i] & (1ll << (k))) == 0),
          chmin(f[k + 1][to], f[k][i] + ad);
    lst.clear();
    for (auto num : now[0]) lst.push_back(num);
    for (auto num : now[1]) lst.push_back(num);
  }
  write(f[60][n]);
}
};  // namespace mine
signed main() {
  srand(time(0));
  mine::main();
}

```