#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
inline bool smin(T &a, const T &b) {
  return a > b ? a = b : a;
}
template <typename T>
inline bool smax(T &a, const T &b) {
  return a < b ? a = b : a;
}
const long long N = (long long)1e5 + 5, mod = (long long)0;
long long dp[N], odp[N], a[N], o[N], b[N], sum[N];
long long cmp(long long first, long long second) {
  return b[first] > b[second];
}
int32_t main() {
  long long n;
  cin >> n;
  for (long long j = 0; j < n; ++j) cin >> a[j], o[j] = j;
  memset(dp, 63, sizeof dp);
  dp[0] = 0;
  for (long long bit = 0; bit < 62; ++bit) {
    memcpy(odp, dp, sizeof dp);
    memset(dp, 63, sizeof dp);
    for (long long j = 0; j < n; ++j) {
      b[j] = a[j] & ((1ll << (bit)) - 1);
    }
    sort(o, o + n, cmp);
    for (long long j = 0; j < n; ++j) {
      long long i = o[j];
      sum[j + 1] = sum[j] + (a[i] >> bit & 1);
    }
    for (long long over = 0; over <= n; ++over) {
      long long cur_nover = sum[over];
      long long ones = over - sum[over] + sum[n] - sum[over];
      long long zeros = n - ones;
      {
        long long add = ones;
        long long nover = cur_nover + add;
        dp[nover] = min(dp[nover], odp[over] + add);
      }
      {
        long long add = zeros;
        long long nover = cur_nover;
        dp[nover] = min(dp[nover], odp[over] + add);
      }
    }
  }
  cout << dp[0] << '\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>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
inline bool smin(T &a, const T &b) {
  return a > b ? a = b : a;
}
template <typename T>
inline bool smax(T &a, const T &b) {
  return a < b ? a = b : a;
}
const long long N = (long long)1e5 + 5, mod = (long long)0;
long long dp[N], odp[N], a[N], o[N], b[N], sum[N];
long long cmp(long long first, long long second) {
  return b[first] > b[second];
}
int32_t main() {
  long long n;
  cin >> n;
  for (long long j = 0; j < n; ++j) cin >> a[j], o[j] = j;
  memset(dp, 63, sizeof dp);
  dp[0] = 0;
  for (long long bit = 0; bit < 62; ++bit) {
    memcpy(odp, dp, sizeof dp);
    memset(dp, 63, sizeof dp);
    for (long long j = 0; j < n; ++j) {
      b[j] = a[j] & ((1ll << (bit)) - 1);
    }
    sort(o, o + n, cmp);
    for (long long j = 0; j < n; ++j) {
      long long i = o[j];
      sum[j + 1] = sum[j] + (a[i] >> bit & 1);
    }
    for (long long over = 0; over <= n; ++over) {
      long long cur_nover = sum[over];
      long long ones = over - sum[over] + sum[n] - sum[over];
      long long zeros = n - ones;
      {
        long long add = ones;
        long long nover = cur_nover + add;
        dp[nover] = min(dp[nover], odp[over] + add);
      }
      {
        long long add = zeros;
        long long nover = cur_nover;
        dp[nover] = min(dp[nover], odp[over] + add);
      }
    }
  }
  cout << dp[0] << '\n';
}

```