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 = 262144 + 50;
long long Ans;
int L, n, a[N], fa[N], cur[N], siz;
inline int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }
inline void Merge(int x, int y) {
  x = Find(x), y = Find(y);
  fa[x] = y;
}
struct data {
  int v, id;
  data(int vv = 0, int iid = 0) { v = vv, id = iid; }
  bool operator<(data w) const { return v < w.v; }
  bool operator>(data w) const { return v > w.v; }
  bool operator>=(data w) const { return v >= w.v; }
  bool operator<=(data w) const { return v <= w.v; }
};
data mx1[N], mx2[N], qwqwq(-999999, 0);
int f1[N], f2[N];
bool vis[N];
inline void init() {
  int i;
  for (i = 0; i <= L; ++i) mx1[i] = mx2[i] = qwqwq, vis[i] = 0;
}
inline void upd(int x, data v, int f) {
  if (f == -1) return;
  if (f1[x] == f) {
    mx1[x] = max(mx1[x], v);
    return;
  }
  if (f2[x] == f) {
    if (v >= mx1[x])
      swap(mx1[x], mx2[x]), swap(f1[x], f2[x]), mx1[x] = max(mx1[x], v);
    else
      mx2[x] = max(mx2[x], v);
    return;
  }
  if (v > mx1[x])
    mx2[x] = mx1[x], f2[x] = f1[x], mx1[x] = v, f1[x] = f;
  else if (v > mx2[x])
    mx2[x] = v, f2[x] = f;
}
inline void dp() {
  register int i, x, y;
  for (x = 0; x <= L; ++x)
    for (y, i = 0; i < 18; ++i)
      if (x >> i & 1)
        y = x ^ (1 << i), upd(x, mx1[y], f1[y]), upd(x, mx2[y], f2[y]);
}
struct Edge {
  int x, y;
  Edge(int xx = 0, int yy = 0) { x = xx, y = yy; }
  bool operator<(Edge w) const { return a[x] + a[y] < a[w.x] + a[w.y]; }
};
Edge ans[N], qwq(0, 0);
Edge w[N];
int lw;
inline void solve() {
  int i, s, c, u, v;
  Edge tmp;
  init();
  for (i = 1; i <= n; ++i)
    cur[i] = Find(i), ans[i] = qwq, upd(a[i], data(a[i], i), cur[i]);
  dp();
  for (i = 1; i <= n; ++i) {
    c = cur[i], s = L ^ a[i], tmp.x = i, tmp.y = 0;
    if (f1[s] == c) {
      if (f2[s] != -1) tmp.y = mx2[s].id;
    } else if (f1[s] != -1)
      tmp.y = mx1[s].id;
    ans[c] = max(ans[c], tmp);
  }
  for (lw = 0, i = 1; i <= n; ++i) {
    c = cur[i];
    if (ans[c].x && ans[c].y) {
      w[++lw] = ans[c];
      ans[c] = qwq;
    }
  }
  sort(w + 1, w + lw + 1);
  for (i = lw; i; --i) {
    u = w[i].x, v = w[i].y;
    if (Find(u) != Find(v)) Merge(u, v), Ans += a[u] + a[v], --siz;
  }
}
int main() {
  int i;
  cin >> n;
  ++n;
  siz = n;
  a[0] = -999999, a[1] = 0;
  for (i = 2; i <= n; ++i) cin >> a[i];
  for (i = 1; i <= n; ++i) L |= a[i], Ans -= a[i], fa[i] = i, cur[i] = i;
  while (siz > 1) solve();
  cout << Ans << endl;
  return 0;
}