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 <typename T>
void r1(T &x) {
  x = 0;
  char c(getchar());
  int f(1);
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; '0' <= c && c <= '9'; c = getchar()) x = (x * 10) + (c ^ 48);
  x *= f;
}
template <typename T, typename... Args>
inline void r1(T &t, Args &...args) {
  r1(t);
  r1(args...);
}
const int maxn = 2e5 + 5;
int n;
long long ans;
int fa[maxn], siz[maxn], v[maxn];
int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); }
bool merge(int u, int v) {
  int s1 = getfa(u), s2 = getfa(v);
  if (s1 == s2) return false;
  if (siz[s1] > siz[s2]) swap(s1, s2);
  fa[s1] = s2, siz[s2] += siz[s1];
  return true;
}
const int maxm = (1 << 18) + 5;
const int N = 18, z = (1 << 18);
pair<int, int> sum[maxm][2], mx[maxn];
void update(pair<int, int> a[2], pair<int, int> b[2]) {
  for (int i = 0; i < 2; ++i) {
    pair<int, int> t = b[i];
    if (a[0].first < t.first ||
        (a[0].first == t.first && a[0].second != t.second)) {
      if (a[0].second != t.second) a[1] = a[0];
      a[0] = t;
    } else if (a[1].first < t.first && (t.second != a[0].second))
      a[1] = t;
  }
}
signed main() {
  int i, j;
  r1(n);
  for (i = 1; i <= n + 1; ++i) fa[i] = i, siz[i] = 1;
  ans = 0;
  for (i = 1; i <= n; ++i) r1(v[i]), ans -= v[i];
  int ct(n);
  while (ct > 0) {
    for (i = 0; i < z; ++i) sum[i][0] = sum[i][1] = make_pair(-1, -1);
    for (i = 1; i <= n + 1; ++i) {
      int s1 = getfa(i), w = v[i];
      if (sum[w][0].second == -1)
        sum[w][0] = make_pair(w, s1);
      else if (sum[w][1].second == -1 && sum[w][0].second != s1)
        sum[w][1] = make_pair(w, s1);
    }
    for (i = 0; i < N; ++i) {
      for (int S = 0; S < z; ++S)
        if ((S >> i) & 1) {
          update(sum[S], sum[S ^ (1 << i)]);
        }
    }
    for (i = 1; i <= n + 1; ++i) mx[i] = make_pair(-1, -1);
    for (i = 1; i <= n + 1; ++i) {
      int nv = (z - 1) ^ v[i], s1 = getfa(i);
      if (sum[nv][0].second == -1) continue;
      if (sum[nv][0].first + v[i] > mx[s1].first && sum[nv][0].second != s1)
        mx[s1] = sum[nv][0], mx[s1].first += v[i];
      if (sum[nv][1].first + v[i] > mx[s1].first && sum[nv][1].second != s1)
        mx[s1] = sum[nv][1], mx[s1].first += v[i];
    }
    for (i = 1; i <= n + 1; ++i)
      if (getfa(i) == i && mx[i].second != -1 && merge(mx[i].second, i)) {
        --ct, ans += mx[i].first;
      }
  }
  printf("%lld\n", ans);
  return 0;
}