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>
#pragma GCC optimize("O2")
using namespace std;
const int N = 2e5 + 10;
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
const long long inf = 1e9;
const int LOG = 18;
long long pw(long long a, long long b, long long M) {
  return (!b ? 1
             : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M
                      : pw(a * a % M, b / 2, M)));
}
int n, A[N], par[N], sz[N];
pair<pair<int, int>, pair<int, int> > dp[1 << LOG];
void upd(int i, pair<int, int> x) {
  if (dp[i].first.second == x.second) {
    dp[i].first.first = max(dp[i].first.first, x.first);
  } else if (dp[i].second.second == x.second) {
    dp[i].second.first = max(dp[i].second.first, x.first);
  } else {
    if (dp[i].first.first < x.first) {
      dp[i].second = dp[i].first;
      dp[i].first = x;
    } else {
      dp[i].second = max(dp[i].second, x);
    }
  }
  if (dp[i].first.first < dp[i].second.first) swap(dp[i].first, dp[i].second);
}
int get(int x) { return (x == par[x] ? x : par[x] = get(par[x])); }
bool unify(int v, int u) {
  v = get(v), u = get(u);
  if (v == u) return 0;
  if (sz[u] > sz[v]) swap(u, v);
  par[u] = v;
  sz[v] += sz[u];
  return 1;
}
int main() {
  scanf("%d", &n);
  long long tot = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
    tot -= A[i];
  }
  A[n + 1] = 0;
  n++;
  iota(par, par + N, 0);
  fill(sz, sz + N, 1);
  for (int T = 0; T < LOG + 2; T++) {
    vector<pair<int, int> > Mx(n + 1, {0, 0});
    for (int i = 0; i < 1 << LOG; i++) dp[i] = {{-inf, 0}, {-inf, 0}};
    for (int i = 1; i <= n; i++) {
      upd(A[i], make_pair(A[i], get(i)));
    }
    for (int mask = 0; mask < 1 << LOG; mask++) {
      for (int i = 0; i < LOG; i++) {
        if (mask >> i & 1) {
          upd(mask, dp[mask ^ (1 << i)].first);
          upd(mask, dp[mask ^ (1 << i)].second);
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      int j = get(i);
      int msk = ((1 << LOG) - 1) ^ A[i];
      pair<int, int> cu = dp[msk].first;
      if (cu.second == j) cu = dp[msk].second;
      if (Mx[j].first <= cu.first + A[i]) {
        Mx[j] = make_pair(cu.first + A[i], cu.second);
      }
    }
    for (int i = 1; i <= n; i++) {
      if (i == get(i)) {
        if (unify(i, Mx[i].second)) {
          tot += Mx[i].first;
        }
      }
    }
  }
  printf("%lld\n", tot);
  return 0;
}