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 N = 200010;
int a[N], n, t;
long long ans = 0;
struct edge {
  int x, y, c;
} s[N];
vector<int> V[N];
int fa[N], mmax[262144], cmax[262144];
int len = 0;
int findpa(int x) { return fa[x] != x ? fa[x] = findpa(fa[x]) : x; }
void BK() {
  int tmp = 0, b, c;
  len = 0;
  memset(mmax, -1, sizeof(mmax));
  memset(cmax, -1, sizeof(cmax));
  for (int i = 1; i <= n; i++)
    if (mmax[a[i]] != -1 && fa[i] != fa[mmax[a[i]]])
      cmax[a[i]] = i;
    else
      mmax[a[i]] = i;
  for (int i = 0; i < 262144; i++) {
    for (int j = 0; j < 18; j++)
      if (i & (1 << j)) {
        int tmp = (i ^ (1 << j));
        if (mmax[tmp] == -1) continue;
        if (mmax[i] == -1) {
          mmax[i] = mmax[tmp], cmax[i] = cmax[tmp];
          continue;
        }
        if (fa[mmax[tmp]] == fa[mmax[i]]) {
          if (a[mmax[i]] < a[mmax[tmp]]) mmax[i] = mmax[tmp];
        } else if (a[mmax[i]] < a[mmax[tmp]])
          cmax[i] = mmax[i], mmax[i] = mmax[tmp];
        else if (cmax[i] == -1 || a[mmax[tmp]] > a[cmax[i]])
          cmax[i] = mmax[tmp];
        if (cmax[tmp] != -1 && fa[cmax[tmp]] != fa[mmax[i]] &&
            (cmax[i] == -1 || a[cmax[tmp]] > a[cmax[i]]))
          cmax[i] = cmax[tmp];
      }
  }
  for (int i = 1; i <= n; i++)
    if (V[i].size()) {
      b = c = 0;
      for (int j = 0; j < V[i].size(); j++) {
        tmp = (262143 ^ a[V[i][j]]);
        if (mmax[tmp] != -1 && fa[mmax[tmp]] != i &&
            a[b] + a[c] <= a[V[i][j]] + a[mmax[tmp]])
          b = V[i][j], c = mmax[tmp];
        else if (cmax[tmp] != -1 && fa[cmax[tmp]] != i &&
                 a[b] + a[c] <= a[V[i][j]] + a[cmax[tmp]])
          c = cmax[tmp], b = V[i][j];
      }
      if (c) s[++len] = (edge){fa[b], fa[c], a[b] + a[c]};
    }
  for (int i = 1; i <= len; i++) {
    int fx = findpa(s[i].x), fy = findpa(s[i].y);
    if (fx == fy) continue;
    ans += s[i].c;
    if (V[fx].size() < V[fy].size()) swap(fx, fy);
    for (int k = 0; k < V[fy].size(); k++) V[fx].push_back(V[fy][k]);
    V[fy].clear();
    fa[fy] = fx;
    t--;
  }
  for (int i = 1; i <= n; i++) findpa(i);
  if (t) BK();
}
int main() {
  scanf("%d", &n);
  t = n;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), ans -= a[i], V[i].push_back(i), fa[i] = i;
  V[++n].push_back(n), fa[n] = n;
  BK();
  printf("%lld\n", ans);
}