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("Ofast,unroll-loops,fast-math")
using namespace std;
long long poww(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}
const long long inf = 9223372036854775807;
const long long mod = 1e9 + 7;
const int lg = 18;
const int maxn = (1 << lg) + 5;
const int bk = (1 << lg) - 1;
long long n, a[maxn], ans, mxs = 1, cur, ls, sz[maxn], par[maxn];
pair<long long, long long> dp[2][maxn], mx[maxn], p;
void prep() {
  for (int i = 0; i < maxn; i++) {
    par[i] = i;
    sz[i] = 1;
  }
}
int getpar(int v) { return par[v] == v ? v : par[v] = getpar(par[v]); }
void merge(int u, int v) {
  u = getpar(u);
  v = getpar(v);
  if (u == v) return;
  if (sz[u] < sz[v]) swap(u, v);
  par[v] = u;
  sz[u] += sz[v];
}
bool check() {
  for (int i = 1; i <= n; i++) {
    if (getpar(i) != getpar(0)) return true;
  }
  return false;
}
void upd(int msk) {
  if (p > dp[0][msk]) {
    if (dp[0][msk].second == p.second) {
      dp[0][msk].first = p.first;
    } else {
      dp[1][msk] = dp[0][msk];
      dp[0][msk] = p;
    }
  } else {
    if (p.second != dp[0][msk].second && p > dp[1][msk]) {
      dp[1][msk] = p;
    }
  }
}
void reset() {
  for (int i = 0; i < maxn; i++) {
    dp[0][i] = dp[1][i] = {-1, -1};
  }
  for (int i = 0; i <= n; i++) {
    p = {a[i], getpar(i)};
    upd(a[i]);
  }
  for (int i = 0; i < lg; i++) {
    for (int msk = 0; msk < (1 << lg); msk++) {
      if (msk & (1 << i)) {
        p = dp[0][msk ^ (1 << i)];
        upd(msk);
        p = dp[1][msk ^ (1 << i)];
        upd(msk);
      }
    }
  }
  for (int i = 0; i <= n; i++) {
    mx[i] = {-1, -1};
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ans -= a[i];
  }
  prep();
  while (check()) {
    reset();
    for (int i = 0; i <= n; i++) {
      cur = bk ^ a[i];
      if (dp[0][cur].second != getpar(i) && dp[0][cur].second != -1) {
        p = {a[i] + dp[0][cur].first, dp[0][cur].second};
        mx[getpar(i)] = max(mx[getpar(i)], p);
      } else if (dp[1][cur].second != getpar(i) && dp[1][cur].second != -1) {
        p = {a[i] + dp[1][cur].first, dp[1][cur].second};
        mx[getpar(i)] = max(mx[getpar(i)], p);
      }
    }
    for (int i = 0; i <= n; i++) {
      if (getpar(i) == i) {
        ls = sz[i];
        merge(i, mx[i].second);
        if (ls != sz[i] || getpar(i) != i) {
          ans += mx[i].first;
        }
      }
    }
  }
  cout << ans;
}