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,unroll-loops")
using namespace std;
const int inf = 1000000010;
const int MAXN = 200010, LOG = 18;
int n, m, k, u, v, x, y, t, a, b;
long long ans;
int A[MAXN];
int par[MAXN], comp;
pair<int, int> dp[1 << LOG];
vector<int> vec[MAXN];
int get(int x) {
  if (par[x] == x) return x;
  return par[x] = get(par[x]);
}
void join(int x, int y, int w) {
  x = get(x);
  y = get(y);
  if (x == y) return;
  comp--;
  ans += w;
  par[y] = x;
}
inline pair<int, int> combine(pair<int, int> i, pair<int, int> j) {
  if (i.first < j.first) swap(i, j);
  if (get(i.first) != get(j.first) && j.first > i.second)
    swap(i.second, j.first);
  if (get(i.first) != get(j.second) && j.second > i.second)
    swap(i.second, j.second);
  return i;
}
int main() {
  ios_base::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];
  A[0] = -inf;
  sort(A + 1, A + n + 2);
  iota(par, par + n + 2, 0);
  comp = n + 1;
  while (comp > 1) {
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n + 1; i++)
      dp[A[i]] = combine(dp[A[i]], pair<int, int>(i, 0));
    for (int j = 0; j < LOG; j++)
      for (int i = (1 << LOG) - 1; ~i; i--)
        if (i & (1 << j)) dp[i] = combine(dp[i], dp[i ^ (1 << j)]);
    for (int i = 1; i <= n + 1; i++) vec[get(i)].push_back(i);
    for (int i = 1; i <= n + 1; i++)
      if (par[i] == i) {
        pair<int, int> e = {-inf, -1};
        for (int x : vec[i]) {
          int tmp = (1 << LOG) - 1 - A[x];
          if (get(dp[tmp].first) == i)
            e = max(e,
                    pair<int, int>(A[dp[tmp].second] + A[x], dp[tmp].second));
          else
            e = max(e, pair<int, int>(A[dp[tmp].first] + A[x], dp[tmp].first));
        }
        join(i, e.second, e.first);
        vec[i].clear();
      }
  }
  cout << ans << '\n';
  return 0;
}