#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int LOG = 60;
const long long INF = (1ll << 60);
int n;
long long a[N];
int id[LOG][N];
int pos[LOG][N];
long long dp[LOG][N];
inline int getBit(long long u, int v) { return (u >> v) & 1; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long maxVal = *max_element(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    a[i] = maxVal - a[i];
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    id[0][i] = i;
    pos[0][i] = i;
  }
  for (int i = 1; i < LOG; i++) {
    int numZero = 0;
    for (int j = 1; j <= n; j++) {
      numZero += getBit(a[id[i - 1][j]], i - 1) == 0;
    }
    int cnt[2] = {0, 0};
    for (int j = 1; j <= n; j++) {
      int idNow = id[i - 1][j];
      int foo = getBit(a[idNow], i - 1);
      cnt[foo]++;
      int now = cnt[foo] + foo * numZero;
      id[i][now] = idNow;
      pos[i][idNow] = now;
    }
  }
  for (int i = 1; i <= n; i++) {
    dp[0][i] = INF;
  }
  dp[0][n + 1] = 0;
  for (int i = 0; i + 1 < LOG; i++) {
    for (int j = 1; j <= n + 1; j++) {
      dp[i + 1][j] = INF;
    }
    int need = 0;
    for (int j = 1; j <= n; j++) {
      int idNow = id[i][j];
      need += getBit(a[idNow], i);
    }
    int minVal = n + 1;
    for (int j = n + 1; j; j--) {
      if (j <= n) {
        int idNow = id[i][j];
        int foo = getBit(a[idNow], i);
        if (!foo) {
          need++;
        } else {
          need--;
          minVal = min(minVal, pos[i + 1][idNow]);
        }
      }
      dp[i + 1][minVal] = min(dp[i + 1][minVal], dp[i][j] + need);
    }
    need = 0;
    minVal = n + 1;
    for (int j = 1; j <= n; j++) {
      int idNow = id[i][j];
      int foo = getBit(a[idNow], i);
      need += (foo == 0);
      if (foo) minVal = min(minVal, pos[i + 1][idNow]);
    }
    for (int j = n + 1; j; j--) {
      if (j <= n) {
        int idNow = id[i][j];
        int foo = 1 - getBit(a[idNow], i);
        if (!foo) {
          need++;
        } else {
          need--;
          minVal = min(minVal, pos[i + 1][idNow]);
        }
      }
      dp[i + 1][minVal] = min(dp[i + 1][minVal], dp[i][j] + need);
    }
  }
  long long res = INF;
  for (int i = 1; i <= n + 1; i++) {
    res = min(res, dp[LOG - 1][i] + n + 1 - i);
  }
  cout << res << endl;
  return 0;
}

### 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;
const int N = 100010;
const int LOG = 60;
const long long INF = (1ll << 60);
int n;
long long a[N];
int id[LOG][N];
int pos[LOG][N];
long long dp[LOG][N];
inline int getBit(long long u, int v) { return (u >> v) & 1; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long maxVal = *max_element(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    a[i] = maxVal - a[i];
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    id[0][i] = i;
    pos[0][i] = i;
  }
  for (int i = 1; i < LOG; i++) {
    int numZero = 0;
    for (int j = 1; j <= n; j++) {
      numZero += getBit(a[id[i - 1][j]], i - 1) == 0;
    }
    int cnt[2] = {0, 0};
    for (int j = 1; j <= n; j++) {
      int idNow = id[i - 1][j];
      int foo = getBit(a[idNow], i - 1);
      cnt[foo]++;
      int now = cnt[foo] + foo * numZero;
      id[i][now] = idNow;
      pos[i][idNow] = now;
    }
  }
  for (int i = 1; i <= n; i++) {
    dp[0][i] = INF;
  }
  dp[0][n + 1] = 0;
  for (int i = 0; i + 1 < LOG; i++) {
    for (int j = 1; j <= n + 1; j++) {
      dp[i + 1][j] = INF;
    }
    int need = 0;
    for (int j = 1; j <= n; j++) {
      int idNow = id[i][j];
      need += getBit(a[idNow], i);
    }
    int minVal = n + 1;
    for (int j = n + 1; j; j--) {
      if (j <= n) {
        int idNow = id[i][j];
        int foo = getBit(a[idNow], i);
        if (!foo) {
          need++;
        } else {
          need--;
          minVal = min(minVal, pos[i + 1][idNow]);
        }
      }
      dp[i + 1][minVal] = min(dp[i + 1][minVal], dp[i][j] + need);
    }
    need = 0;
    minVal = n + 1;
    for (int j = 1; j <= n; j++) {
      int idNow = id[i][j];
      int foo = getBit(a[idNow], i);
      need += (foo == 0);
      if (foo) minVal = min(minVal, pos[i + 1][idNow]);
    }
    for (int j = n + 1; j; j--) {
      if (j <= n) {
        int idNow = id[i][j];
        int foo = 1 - getBit(a[idNow], i);
        if (!foo) {
          need++;
        } else {
          need--;
          minVal = min(minVal, pos[i + 1][idNow]);
        }
      }
      dp[i + 1][minVal] = min(dp[i + 1][minVal], dp[i][j] + need);
    }
  }
  long long res = INF;
  for (int i = 1; i <= n + 1; i++) {
    res = min(res, dp[LOG - 1][i] + n + 1 - i);
  }
  cout << res << endl;
  return 0;
}

```