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;
template <class T = int>
T read() {
  T x = 0;
  char ch = 0;
  bool f = false;
  while (!isdigit(ch)) f |= (ch = getchar()) == '-';
  for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ '0');
  return f ? -x : x;
}
const int N = 2.1e5;
const int L = 18;
const int X = 1 << L;
void dmax(int &a, int b) { a = max(a, b); }
struct P {
  int val, id;
};
bool operator<(P a, P b) { return a.val < b.val; }
void ins(P a[2], P b) {
  if (b.id == -1) return;
  for (int i = 0; i < (int)(2); i++) {
    if (b.id == a[i].id) {
      dmax(a[i].val, b.val);
      return;
    }
  }
  for (int i = 0; i < (int)(2); i++)
    if (a[i] < b) swap(a[i], b);
}
void ins2(P a[2], P b[2]) {
  for (int i = 0; i < (int)(2); i++) ins(a, b[i]);
}
P q(P a[2], int id) { return a[id == a[0].id]; }
P sols[X][2];
void qaq() {
  for (int i = 0; i < (int)(L); i++) {
    int v = 1 << i;
    int v2 = v << 1;
    for (int j = 0; j < X; j += v2) {
      for (int k = 0; k < (int)(v); k++) ins2(sols[j + k + v], sols[j + k]);
    }
  }
}
struct U {
  int fa[N];
  int f(int x) { return fa[x] ? fa[x] = f(fa[x]) : x; }
  bool u(int x, int y) {
    x = f(x);
    y = f(y);
    if (x == y) return false;
    fa[x] = y;
    return true;
  }
} u;
long long ans = 0;
P b[N];
int a[N];
int main() {
  int n = read();
  for (int i = (int)(1); i <= (int)(n); i++) a[i] = read();
  n++;
  while (true) {
    vector<int> nd;
    for (int i = (int)(1); i <= (int)(n); i++)
      if (u.f(i) == i) nd.push_back(i);
    if (nd.size() == 1) break;
    for (int i = 0; i < (int)(X); i++)
      for (int j = 0; j < (int)(2); j++) sols[i][j] = {-1, -1};
    for (int i = (int)(1); i <= (int)(n); i++) ins(sols[a[i]], {a[i], u.f(i)});
    qaq();
    for (int i = (int)(1); i <= (int)(n); i++) b[i] = {-1, -1};
    for (int i = (int)(1); i <= (int)(n); i++) {
      int f = u.f(i);
      P p = q(sols[(X - 1) ^ a[i]], f);
      if (p.id != -1) b[f] = max(b[f], {p.val + a[i], p.id});
    }
    for (int v : nd) {
      if (b[v].id != -1) {
        if (u.u(v, b[v].id)) ans += b[v].val;
      }
    }
  }
  for (int i = (int)(1); i <= (int)(n); i++) ans -= a[i];
  printf("%lld\n", ans);
  return 0;
}