#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) {
    if (vi != v.begin()) os << ", ";
    os << *vi;
  }
  os << "}";
  return os;
}
const int BITS = 58;
const int INF = 1e9 + 5;
int N;
vector<long long> A;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  A.resize(N);
  for (auto &a : A) cin >> a;
  vector<int> dp(N + 1, INF), next_dp(N + 1);
  dp[0] = 0;
  vector<long long> zeros(N), ones(N);
  for (int bit = 0; bit < BITS; bit++) {
    next_dp.assign(N + 1, INF);
    int zero_count = 0, one_count = 0;
    int zero_carry = 0, one_carry = 0;
    int zero = 0, one = 0;
    for (int i = 0; i < N; i++)
      if (A[i] >> bit & 1) {
        one_count++;
        zero_carry++;
        ones[one++] = A[i];
      } else {
        zero_count++;
        zeros[zero++] = A[i];
      }
    for (int carry = 0; carry <= N; carry++) {
      next_dp[one_carry] = min(next_dp[one_carry], dp[carry] + zero_count);
      next_dp[zero_carry] = min(next_dp[zero_carry], dp[carry] + one_count);
      if (carry < N) {
        if (A[carry] >> bit & 1) {
          zero_count++;
          one_count--;
          one_carry++;
        } else {
          one_count++;
          zero_count--;
          zero_carry++;
        }
      }
    }
    swap(dp, next_dp);
    int n = 0;
    for (int i = 0; i < one; i++) A[n++] = ones[i];
    for (int i = 0; i < zero; i++) A[n++] = zeros[i];
  }
  cout << min(dp[0], dp[N]) << '\n';
}

### 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 <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) {
    if (vi != v.begin()) os << ", ";
    os << *vi;
  }
  os << "}";
  return os;
}
const int BITS = 58;
const int INF = 1e9 + 5;
int N;
vector<long long> A;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  A.resize(N);
  for (auto &a : A) cin >> a;
  vector<int> dp(N + 1, INF), next_dp(N + 1);
  dp[0] = 0;
  vector<long long> zeros(N), ones(N);
  for (int bit = 0; bit < BITS; bit++) {
    next_dp.assign(N + 1, INF);
    int zero_count = 0, one_count = 0;
    int zero_carry = 0, one_carry = 0;
    int zero = 0, one = 0;
    for (int i = 0; i < N; i++)
      if (A[i] >> bit & 1) {
        one_count++;
        zero_carry++;
        ones[one++] = A[i];
      } else {
        zero_count++;
        zeros[zero++] = A[i];
      }
    for (int carry = 0; carry <= N; carry++) {
      next_dp[one_carry] = min(next_dp[one_carry], dp[carry] + zero_count);
      next_dp[zero_carry] = min(next_dp[zero_carry], dp[carry] + one_count);
      if (carry < N) {
        if (A[carry] >> bit & 1) {
          zero_count++;
          one_count--;
          one_carry++;
        } else {
          one_count++;
          zero_count--;
          zero_carry++;
        }
      }
    }
    swap(dp, next_dp);
    int n = 0;
    for (int i = 0; i < one; i++) A[n++] = ones[i];
    for (int i = 0; i < zero; i++) A[n++] = zeros[i];
  }
  cout << min(dp[0], dp[N]) << '\n';
}

```