#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < (int)(n); ++i) cin >> a[i];
  sort((a).begin(), (a).end());
  vector<long long> b(n);
  for (int i = 0; i < (int)(n); ++i) b[i] = a[n - 1] - a[n - i - 1];
  vector<pair<long long, long long> > x(n);
  for (int i = 0; i < (int)(n); ++i) x[i] = {a[i], i};
  for (int b = (int)(60) - 1; b >= 0; --b) {
    int lh = 0;
    long long half = 1LL << b;
    while (lh < n && x[lh].first < half) ++lh;
    long long ladd = x[0].second, radd = lh < n ? x[lh].second : x[0].second;
    int L = 0, R = lh;
    vector<pair<long long, long long> > nx;
    while (L < lh || R < n) {
      if (R == n || (L < lh && x[L].first <= x[R].first - half)) {
        nx.push_back({x[L].first, min(radd + n - R + L, ladd + R - L)});
        ++L;
        ladd = L < n ? x[L].second : x[0].second;
      } else {
        nx.push_back({x[R].first - half, min(radd + n - R + L, ladd + R - L)});
        ++R;
        radd = R < n ? x[R].second : x[0].second;
      }
    }
    x = nx;
  }
  cout << x[0].second << '\n';
  return 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>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < (int)(n); ++i) cin >> a[i];
  sort((a).begin(), (a).end());
  vector<long long> b(n);
  for (int i = 0; i < (int)(n); ++i) b[i] = a[n - 1] - a[n - i - 1];
  vector<pair<long long, long long> > x(n);
  for (int i = 0; i < (int)(n); ++i) x[i] = {a[i], i};
  for (int b = (int)(60) - 1; b >= 0; --b) {
    int lh = 0;
    long long half = 1LL << b;
    while (lh < n && x[lh].first < half) ++lh;
    long long ladd = x[0].second, radd = lh < n ? x[lh].second : x[0].second;
    int L = 0, R = lh;
    vector<pair<long long, long long> > nx;
    while (L < lh || R < n) {
      if (R == n || (L < lh && x[L].first <= x[R].first - half)) {
        nx.push_back({x[L].first, min(radd + n - R + L, ladd + R - L)});
        ++L;
        ladd = L < n ? x[L].second : x[0].second;
      } else {
        nx.push_back({x[R].first - half, min(radd + n - R + L, ladd + R - L)});
        ++R;
        radd = R < n ? x[R].second : x[0].second;
      }
    }
    x = nx;
  }
  cout << x[0].second << '\n';
  return 0;
}

```