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 Lg = 18, maxn = (1 << Lg) + 10;
int a[maxn];
long long ans;
int col[maxn], pr[maxn];
pair<int, pair<int, int> > bst[maxn];
pair<int, int> dp[maxn];
int fnd(int u) { return pr[u] < 0 ? u : pr[u] = fnd(pr[u]); }
void mrg(int x, int y) {
  if (fnd(x) == fnd(y)) return;
  ans += a[x] + a[y];
  x = fnd(x), y = fnd(y);
  if (pr[x] > pr[y]) swap(x, y);
  pr[x] += pr[y];
  pr[y] = x;
}
void add(int pos, int id) {
  if (dp[pos].first != -1 && col[id] == col[dp[pos].first]) {
    if (a[dp[pos].first] < a[id]) dp[pos].first = id;
    return;
  }
  if (dp[pos].second != -1 && col[id] == col[dp[pos].second]) {
    if (a[dp[pos].second] < a[id]) dp[pos].second = id;
    return;
  }
  if (dp[pos].first == -1 || a[dp[pos].first] < a[id]) {
    dp[pos].second = dp[pos].first;
    dp[pos].first = id;
  } else if (dp[pos].second == -1 || a[dp[pos].second] < a[id]) {
    dp[pos].second = id;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie();
  memset(pr, -1, sizeof pr);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ans -= a[i];
  }
  a[n++] = 0;
  while (true) {
    bool _ = 1;
    for (int i = 0; i < n; i++) {
      col[i] = fnd(i);
      _ &= col[i] == col[0];
    }
    if (_) break;
    for (int i = 0; i < maxn; i++) dp[i] = {-1, -1}, bst[i] = {-1, {-1, -1}};
    for (int i = 0; i < n; i++) add(a[i], i);
    for (int i = 0; i < Lg; i++) {
      for (int msk = (1 << Lg) - 1; msk >= 0; msk--) {
        if ((((msk) >> (i)) & 1)) {
          if (dp[msk ^ (1 << i)].first != -1)
            add(msk, dp[msk ^ (1 << i)].first);
          if (dp[msk ^ (1 << i)].second != -1)
            add(msk, dp[msk ^ (1 << i)].second);
        }
      }
    }
    for (int i = 0; i < n; i++) {
      int msk = ((1 << Lg) - 1) ^ a[i];
      if (dp[msk].first != -1 && col[dp[msk].first] != col[i])
        bst[col[i]] =
            max(bst[col[i]], (pair<int, pair<int, int> >){
                                 a[i] + a[dp[msk].first], {i, dp[msk].first}});
      if (dp[msk].second != -1 && col[dp[msk].second] != col[i])
        bst[col[i]] = max(bst[col[i]],
                          (pair<int, pair<int, int> >){a[i] + a[dp[msk].second],
                                                       {i, dp[msk].second}});
    }
    for (int i = 0; i < n; i++) {
      if (col[i] == i && bst[i].first != -1)
        mrg(bst[i].second.first, bst[i].second.second);
    }
  }
  return cout << ans << endl, 0;
}