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 MAXN = 4e5 + 10;
const int B = 18;
const int INF = 2e9;
const double PI = acos(-1);
const double eps = 1e-6;
int n, m;
int a[MAXN];
int fa[(1 << B) + 10], siz[(1 << B) + 10];
int buk[(1 << B) + 10];
long long ans;
template <typename T>
inline void read(T &a) {
  a = 0;
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    a = a * 10 + (c ^ 48);
    c = getchar();
  }
  a *= f;
}
int Find(int x) {
  if (fa[x] == x) return x;
  return fa[x] = Find(fa[x]);
}
int Merge(int x, int y) {
  x = Find(x), y = Find(y);
  if (x == y) return false;
  if (siz[x] < siz[y]) swap(x, y);
  siz[x] += siz[y];
  fa[y] = x;
  return true;
}
signed main() {
  read(n);
  for (int i = 0; i < (1 << B); ++i) {
    fa[i] = i;
    siz[i] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    read(a[i]);
    buk[a[i]]++;
    ans -= a[i];
  }
  buk[0]++;
  for (int w = (1 << B) - 1; ~w; --w) {
    for (int x = w, y;; x = ((x - 1) & w)) {
      y = (w ^ x);
      if (buk[x] && buk[y] && Merge(x, y)) {
        ans += 1ll * (buk[x] + buk[y] - 1) * w;
        buk[x] = buk[y] = 1;
      }
      if (!x) break;
    }
  }
  printf("%lld\n", ans);
  return 0;
}