#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, B = 60;
const long long one = 1, inf = 1e15;
long long a[N];
int count_greater_equal(vector<long long> &A, long long target);
int solve(vector<long long> &A, int b, long long v);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  long long mx = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    a[i] = mx - a[i];
  }
  vector<pair<long long, long long> > cand = {{0, 0}};
  for (int b = 0; b < B; ++b) {
    vector<long long> temp;
    for (int i = 1; i <= n; ++i) {
      temp.push_back(a[i] & ((one << (b + 1)) - 1));
    }
    sort(temp.begin(), temp.end());
    int k = cand.size();
    for (int i = 0; i < k; ++i) {
      cand.push_back(cand[i]);
      cand.back().first |= (one << b);
    }
    for (auto &p : cand) {
      p.second += solve(temp, b, p.first);
    }
    sort(cand.begin(), cand.end());
    vector<pair<long long, long long> > new_cand;
    for (auto &p : cand) {
      if (new_cand.empty()) {
        new_cand.push_back(p);
      } else {
        int id1 =
            count_greater_equal(temp, (one << (b + 1)) - new_cand.back().first);
        int id2 = count_greater_equal(temp, (one << (b + 1)) - p.first);
        if (id1 != id2) {
          new_cand.push_back(p);
        } else if (p.second < new_cand.back().second) {
          new_cand.back() = p;
        }
      }
    }
    cand = new_cand;
  }
  vector<long long> temp;
  for (int i = 1; i <= n; ++i) {
    temp.push_back(a[i]);
  }
  sort(temp.begin(), temp.end());
  long long ans = inf;
  for (auto &p : cand) {
    p.second += solve(temp, B, p.first);
    ans = min(ans, p.second);
  }
  cout << ans << '\n';
}
int count_greater_equal(vector<long long> &A, long long target) {
  int n = A.size();
  int lo = 0, hi = n - 1;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (A[mid] >= target) {
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  return n - hi - 1;
}
int solve(vector<long long> &A, int b, long long v) {
  int ans = count_greater_equal(A, (one << b) - v);
  ans -= count_greater_equal(A, (one << (b + 1)) - v);
  ans += count_greater_equal(A, (one << b) + (one << (b + 1)) - v);
  ans -= count_greater_equal(A, (one << (b + 2)) - v);
  return ans;
}

### Prompt

Please provide a Cpp coded solution 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>
using namespace std;
const int N = 1e5 + 10, B = 60;
const long long one = 1, inf = 1e15;
long long a[N];
int count_greater_equal(vector<long long> &A, long long target);
int solve(vector<long long> &A, int b, long long v);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  long long mx = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    a[i] = mx - a[i];
  }
  vector<pair<long long, long long> > cand = {{0, 0}};
  for (int b = 0; b < B; ++b) {
    vector<long long> temp;
    for (int i = 1; i <= n; ++i) {
      temp.push_back(a[i] & ((one << (b + 1)) - 1));
    }
    sort(temp.begin(), temp.end());
    int k = cand.size();
    for (int i = 0; i < k; ++i) {
      cand.push_back(cand[i]);
      cand.back().first |= (one << b);
    }
    for (auto &p : cand) {
      p.second += solve(temp, b, p.first);
    }
    sort(cand.begin(), cand.end());
    vector<pair<long long, long long> > new_cand;
    for (auto &p : cand) {
      if (new_cand.empty()) {
        new_cand.push_back(p);
      } else {
        int id1 =
            count_greater_equal(temp, (one << (b + 1)) - new_cand.back().first);
        int id2 = count_greater_equal(temp, (one << (b + 1)) - p.first);
        if (id1 != id2) {
          new_cand.push_back(p);
        } else if (p.second < new_cand.back().second) {
          new_cand.back() = p;
        }
      }
    }
    cand = new_cand;
  }
  vector<long long> temp;
  for (int i = 1; i <= n; ++i) {
    temp.push_back(a[i]);
  }
  sort(temp.begin(), temp.end());
  long long ans = inf;
  for (auto &p : cand) {
    p.second += solve(temp, B, p.first);
    ans = min(ans, p.second);
  }
  cout << ans << '\n';
}
int count_greater_equal(vector<long long> &A, long long target) {
  int n = A.size();
  int lo = 0, hi = n - 1;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (A[mid] >= target) {
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  return n - hi - 1;
}
int solve(vector<long long> &A, int b, long long v) {
  int ans = count_greater_equal(A, (one << b) - v);
  ans -= count_greater_equal(A, (one << (b + 1)) - v);
  ans += count_greater_equal(A, (one << b) + (one << (b + 1)) - v);
  ans -= count_greater_equal(A, (one << (b + 2)) - v);
  return ans;
}

```