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;
inline long long read() {
  char c = getchar();
  long long x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
struct node {
  long long val, c;
  node(long long xx = -1, long long yy = -1) { val = xx, c = yy; }
  bool operator<(const node& b) const { return val < b.val; }
  bool operator>(const node& b) const { return val > b.val; }
  node operator+(long long xx) {
    node res;
    res.val = val + xx, res.c = c;
    return res;
  }
};
struct pii {
  node mx1, mx2;
  inline void init() { mx1 = mx2 = node(); }
  inline void ins(node c) {
    if (c > mx1) {
      if (mx1.c != c.c) mx2 = mx1;
      mx1 = c;
    }
    if (c > mx2 && c.c != mx1.c) mx2 = c;
  }
};
pii f[262144];
node mx[262144];
long long n, a[262144], ff[262144], res;
inline long long getf(long long x) {
  while (x != ff[x]) x = ff[x] = ff[ff[x]];
  return x;
}
signed main() {
  n = read();
  for (register long long i = (1); i <= (n); ++i) a[i] = read(), res -= a[i];
  a[++n] = 0;
  for (register long long i = (1); i <= (n); ++i) ff[i] = i;
  long long cnt = n, mxs = (1 << 18) - 1;
  while (cnt > 1) {
    for (register long long i = (0); i <= (mxs); ++i) f[i].init();
    for (register long long i = (1); i <= (n); ++i)
      f[a[i]].ins(node(a[i], getf(i)));
    for (register long long i = (0); i <= (17); ++i)
      for (register long long s = (0); s <= (mxs); ++s)
        if (s >> i & 1) {
          long long t = s ^ (1 << i);
          f[s].ins(f[t].mx1), f[s].ins(f[t].mx2);
        }
    for (register long long i = (1); i <= (n); ++i) mx[i] = node();
    for (register long long i = (1); i <= (n); ++i) {
      long long s = mxs ^ a[i], c = getf(i);
      if (f[s].mx1.c != -1 && f[s].mx1.c != c)
        mx[c] = max(mx[c], f[s].mx1 + a[i]);
      if (f[s].mx2.c != -1 && f[s].mx2.c != c)
        mx[c] = max(mx[c], f[s].mx2 + a[i]);
    }
    for (register long long i = (1); i <= (n); ++i)
      if (i == getf(i)) {
        long long v = mx[i].c;
        if (getf(i) == getf(v)) continue;
        ff[getf(i)] = getf(v), cnt--, res += mx[i].val;
      }
  }
  cout << res;
  return 0;
}