Problem: Kuroni isn't good at economics. So he decided to found a new financial pyramid called Antihype. It has the following rules:

  1. You can join the pyramid for free and get 0 coins. 
  2. If you are already a member of Antihype, you can invite your friend who is currently not a member of Antihype, and get a number of coins equal to your age (for each friend you invite). 



n people have heard about Antihype recently, the i-th person's age is a_i. Some of them are friends, but friendship is a weird thing now: the i-th person is a friend of the j-th person if and only if a_i  AND  a_j = 0, where AND denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).

Nobody among the n people is a member of Antihype at the moment. They want to cooperate to join and invite each other to Antihype in a way that maximizes their combined gainings. Could you help them? 

Input

The first line contains a single integer n (1≤ n ≤ 2⋅ 10^5) — the number of people.

The second line contains n integers a_1, a_2, ..., a_n (0≤ a_i ≤ 2⋅ 10^5) — the ages of the people.

Output

Output exactly one integer — the maximum possible combined gainings of all n people.

Example

Input


3
1 2 3


Output


2

Note

Only the first and second persons are friends. The second can join Antihype and invite the first one, getting 2 for it.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);
template <typename T, typename U>
static inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << '(' << p.first << "," << p.second << ')';
}
int _runtimeTerror_() {
  int n;
  cin >> n;
  long long ans = 0;
  vector<int> p(n + 1), r(n + 1, 1), a(n + 1, 0);
  vector<vector<pair<int, int>>> best(
      1 << 18, vector<pair<int, int>>(2, make_pair(-1, -1)));
  vector<pair<int, int>> good(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    p[i] = i, r[i] = 1;
    ans -= a[i];
  }
  function<int(int)> parent = [&](int i) {
    return p[i] == i ? i : parent(p[i]);
  };
  function<bool(int, int)> merge = [&](int x, int y) {
    x = parent(x), y = parent(y);
    if (x == y) return false;
    if (r[x] > r[y]) swap(x, y);
    r[y] += r[x];
    p[x] = y;
    return true;
  };
  const int N = (1 << 18) - 1;
  int cmp = n + 1;
  while (cmp > 1) {
    for (int i = 0; i < (1 << 18); ++i) best[i][0] = best[i][1] = {-1, -1};
    for (int i = 0; i <= n; ++i) {
      good[i] = {-1, -1};
      pair<int, int> u = {a[i], parent(i)};
      if (best[a[i]][0] < u) {
        if (best[a[i]][0].second != u.second) best[a[i]][1] = best[a[i]][0];
        best[a[i]][0] = u;
      } else if (best[a[i]][1] < u && best[a[i]][0].second != u.second)
        best[a[i]][1] = u;
    }
    for (int i = 0; i < 18; ++i) {
      for (int mask = 0; mask < (1 << 18); ++mask) {
        if (mask & (1 << i)) {
          if (best[mask][1] > best[mask ^ (1 << i)][0]) continue;
          if (best[mask][0] < best[mask ^ (1 << i)][0]) {
            pair<int, int> tmp = best[mask][0];
            best[mask][0] = best[mask ^ (1 << i)][0];
            if (tmp > best[mask ^ (1 << i)][1] &&
                tmp.second != best[mask][0].second)
              best[mask][1] = tmp;
            else if (best[mask][1] > best[mask ^ (1 << i)][1] &&
                     best[mask][1].second != best[mask][0].second)
              ;
            else
              best[mask][1] = best[mask ^ (1 << i)][1];
          } else {
            if (best[mask ^ (1 << i)][0] > best[mask][1] &&
                best[mask][0].second != best[mask ^ (1 << i)][0].second)
              best[mask][1] = best[mask ^ (1 << i)][0];
            else if (best[mask ^ (1 << i)][1] > best[mask][1] &&
                     best[mask ^ (1 << i)][1].second != best[mask][0].second)
              best[mask][1] = best[mask ^ (1 << i)][1];
          }
        }
      }
    }
    for (int i = 0; i <= n; ++i) {
      int root = parent(i);
      int cur = a[i] ^ N;
      if (best[cur][0].first != -1 && best[cur][0].second != root)
        amax(good[root],
             make_pair(best[cur][0].first + a[i], best[cur][0].second));
      else if (best[cur][1].first != -1 && best[cur][1].second != root)
        amax(good[root],
             make_pair(best[cur][1].first + a[i], best[cur][1].second));
    }
    for (int i = 0; i <= n; ++i) {
      if (parent(i) != i) continue;
      if (merge(i, good[i].second)) {
        ans += good[i].first;
        --cmp;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) _runtimeTerror_();
  return 0;
}