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 = 2e5 + 100;
const int K = 1 << 18;
struct pr {
  int o, t;
  pr(int _o = -1, int _t = -1) {
    o = _o;
    t = _t;
  }
};
int a[N], d[N], to[N], n, m, k = 18, fa[N];
long long ans;
int c[K];
bool vis[N];
pr dp[K][18], tp[K];
vector<int> p[K];
int get(int x) {
  if (fa[x] == x)
    return x;
  else
    return fa[x] = get(fa[x]);
}
bool unite(int x, int y) {
  x = get(x);
  y = get(y);
  if (x == y) return false;
  fa[x] = y;
  m--;
  return true;
}
bool same(int x, int y) {
  x = get(x);
  y = get(y);
  return x == y;
}
pr merge(pr p, pr q) {
  if (q.o == -1) return p;
  if (p.o == -1) return q;
  if (a[p.o] < a[q.o]) swap(p, q);
  if (!same(p.o, q.o)) {
    if (p.t == -1 || a[p.t] < a[q.o]) p.t = q.o;
  } else if (~q.t) {
    if (p.t == -1 || a[p.t] < a[q.o]) p.t = q.t;
  }
  return p;
}
int main() {
  scanf("%d", &n);
  m = n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    ans -= a[i];
  }
  for (int i = 0; i <= n; ++i) {
    p[a[i]].push_back(i);
    fa[i] = i;
  }
  while (m) {
    for (int s = 0; s < K; ++s) tp[s] = pr();
    for (int s = 0; s < K; ++s) {
      for (auto i : p[s]) {
        int j = get(i);
        if (vis[j]) continue;
        if (tp[s].o == -1)
          tp[s].o = i;
        else if (tp[s].t == -1)
          tp[s].t = i;
        vis[j] = true;
        if (!tp[s].t) break;
      }
      if (~tp[s].o) vis[get(tp[s].o)] = false;
      if (~tp[s].t) vis[get(tp[s].t)] = false;
    }
    for (int s = 0; s < K; ++s) {
      if (s & 1)
        dp[s][0] = merge(tp[s], tp[s ^ 1]);
      else
        dp[s][0] = tp[s];
    }
    for (int s = 0; s < K; ++s) {
      for (int i = 1; i < k; ++i) {
        if (s & (1 << i))
          dp[s][i] = merge(dp[s][i - 1], dp[s ^ (1 << i)][i - 1]);
        else
          dp[s][i] = dp[s][i - 1];
      }
    }
    for (int i = 0; i <= n; ++i) d[i] = -1, to[i] = -1;
    for (int i = 0, j; i <= n; ++i) {
      j = get(i);
      pr &x = dp[(K - 1) ^ a[i]][k - 1];
      if (~x.o && !same(x.o, j) && d[j] < a[x.o] + a[i])
        d[j] = a[x.o] + a[i], to[j] = x.o;
      if (~x.t && !same(x.t, j) && d[j] < a[x.t] + a[i])
        d[j] = a[x.t] + a[i], to[j] = x.t;
    }
    for (int i = 0; i <= n; ++i) {
      if (to[i] == -1 || fa[i] != i) continue;
      if (unite(i, to[i])) ans += d[i];
    }
  }
  printf("%lld\n", ans);
}