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;
using LL = long long;
using pii = pair<int, int>;
const int N = 1 << 18;
const int maxN = 2e5 + 5;
int n;
LL ans;
int a[maxN];
int fa[maxN], size[maxN];
pii large[maxN];
pii best[N + 5][2];
int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }
inline bool Merge(int u, int v) {
  int fu = Find(u), fv = Find(v);
  if (fu == fv) return false;
  if (size[fu] > size[fv]) swap(fu, fv);
  fa[fu] = fv, size[fv] += size[fu];
  return true;
}
inline void Trans(pii A[2], pii B[2]) {
  for (int i = 0; i < 2; ++i) {
    pii t = B[i];
    if (t.first > A[0].first or
        (t.first == A[0].first and t.second != A[0].second)) {
      if (A[0].second != t.second) A[1] = A[0];
      A[0] = t;
    } else if (t.first > A[1].first and t.second != A[0].second)
      A[1] = t;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n + 1; ++i) fa[i] = i, size[i] = 1;
  for (int i = 1; i <= n; ++i) cin >> a[i], ans -= a[i];
  int cnt = n + 1;
  while (cnt > 1) {
    for (int i = 0; i < N; ++i) best[i][0] = best[i][1] = pii(-1, -1);
    for (int i = 1; i <= n + 1; ++i) {
      int id = Find(i);
      if (best[a[i]][0].second == -1)
        best[a[i]][0] = pii(a[i], id);
      else if (best[a[i]][1].second == -1 and best[a[i]][0].second != id)
        best[a[i]][1] = pii(a[i], id);
    }
    for (int i = 0; i < 18; ++i)
      for (int S = 0; S < N; ++S)
        if (S >> i & 1) {
          int T = S ^ 1 << i;
          Trans(best[S], best[T]);
        }
    for (int i = 1; i <= n + 1; ++i) large[i] = pii(-1, -1);
    for (int i = 1; i <= n + 1; ++i) {
      int S = (N - 1) ^ a[i], id = Find(i);
      if ((best[S][0].first ^ a[i]) > large[id].first and
          best[S][0].second != id)
        large[id] = best[S][0], large[id].first ^= a[i];
      if ((best[S][1].first ^ a[i]) > large[id].first and
          best[S][1].second != id)
        large[id] = best[S][1], large[id].first ^= a[i];
    }
    for (int i = 1; i <= n + 1; ++i)
      if (Find(i) == i and large[i].first != -1 and Merge(large[i].second, i))
        --cnt, ans += large[i].first;
  }
  cout << ans << endl;
  return 0;
}