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 char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 200005;
int fa[N];
bitset<1 << 18 | 2> bj;
vector<int> v[1 << 18 | 2];
long long ans;
inline int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }
inline int mer(int x, int y) {
  x = gf(x);
  y = gf(y);
  if (x != y) {
    fa[x] = y;
    return 1;
  }
  return 0;
}
int main() {
  int n = read();
  v[0].push_back(0);
  for (int i = (int)(1); i <= (int)(n); i++) v[read()].push_back(fa[i] = i);
  for (int i = (int)((1 << 18) - 1); i >= (int)(1); i--) {
    int zs = i & -i, jb = i ^ zs;
    for (int j = jb;; j = (j - 1) & jb) {
      if (v[j].size() && v[i - j].size()) {
        if (!bj[j]) {
          for (int k = (int)(1); k <= (int)(v[j].size() - 1); k++)
            ans += mer(v[j][0], v[j][k]) * i;
          bj[j] = 1;
        }
        if (!bj[i - j]) {
          for (auto k : v[i - j]) ans += mer(v[j][0], k) * i;
          bj[i - j] = 1;
        } else
          ans += mer(v[j][0], v[i - j][0]) * i;
      }
      if (!j) break;
    }
  }
  for (int i = (int)(0); i <= (int)((1 << 18) - 1); i++)
    ans -= (long long)v[i].size() * i;
  cout << ans << endl;
}