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 N = 262144 + 50, M = 262144;
int L;
int n, m, cnt[N];
long long ans;
int s[N], now[N];
inline void GetNow(int x) {
  if (now[x] <= 0) return (void)(now[x] = -1);
  now[x] = (now[x] - 1) & s[x];
  while (!cnt[now[x]]) {
    if (!now[x]) return (void)(now[x] = -1);
    now[x] = (now[x] - 1) & s[x];
  }
}
vector<int> G[N];
bool vis[N];
int siz;
int fa[N];
inline int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }
inline void Merge(int x, int y) {
  x = Find(x), y = Find(y);
  fa[x] = y;
}
int main() {
  register int i, j;
  int x;
  cin >> n;
  m = L = 0;
  cnt[0] = 1;
  for (i = 1; i <= n; ++i) cin >> x, m = max(m, x), L |= x, ++cnt[x], ans -= x;
  for (i = 0; i <= m; ++i) s[i] = L ^ i, now[i] = s[i] + 1, fa[i] = i;
  for (i = 0; i <= m; ++i)
    if (cnt[i]) {
      GetNow(i);
      if (now[i] != -1) G[i + now[i]].push_back(i);
    }
  int l, u, v;
  long long k;
  siz = n;
  for (i = L; i >= 0 && siz; --i)
    if (G[i].size()) {
      while (G[i].size()) {
        u = G[i][G[i].size() - 1], v = now[u];
        G[i].pop_back();
        if (Find(u) ^ Find(v)) {
          Merge(u, v);
          if (!vis[u] && !vis[v])
            k = cnt[u] + cnt[v] - 1;
          else if (!vis[u])
            k = cnt[u];
          else if (!vis[v])
            k = cnt[v];
          else
            k = 1;
          ans += k * i;
          siz -= k;
          vis[u] = vis[v] = 1;
        }
        GetNow(u);
        while (now[u] != -1 && Find(u) == Find(now[u])) GetNow(u);
        if (now[u] != -1) G[u + now[u]].push_back(u);
      }
    }
  cout << ans << endl;
  return 0;
}