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 = 2e5 + 5, Maxn = (1 << 20) - 1;
int n, a[maxn], f[maxn], siz[maxn];
long long ans;
struct Data {
  int x, p;
} best[Maxn + 5][2], Max[maxn];
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
void Init() {
  for (int i = 0; i <= Maxn; ++i) best[i][0] = best[i][1] = (Data){-1, -1};
  for (int i = 1; i <= n + 1; ++i) Max[i] = (Data){-1, -1};
}
void solve(Data A[2], Data B[2]) {
  for (int i = 0; i <= 1; ++i) {
    if (B[i].x > A[0].x || (B[i].x == A[0].x && B[i].p != A[0].p)) {
      if (B[i].p != A[0].p) A[1] = A[0];
      A[0] = B[i];
    } else if (B[i].x > A[1].x && B[i].p != A[0].p)
      A[1] = B[i];
  }
}
int main() {
  scanf("%d", &n), f[n + 1] = n + 1, siz[n + 1] = 1;
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]), f[i] = i, siz[i] = 1, ans -= a[i];
  int tot = n;
  while (tot) {
    Init();
    for (int i = 1; i <= n + 1; ++i) {
      int p = find(i), p1 = best[a[i]][0].p, p2 = best[a[i]][1].p;
      if (p1 == -1)
        best[a[i]][0] = (Data){a[i], p};
      else if (p2 == -1 && p1 != p)
        best[a[i]][1] = (Data){a[i], p};
    }
    for (int i = 0; i < 20; ++i)
      for (int s = 0; s <= Maxn; ++s)
        if (s & (1 << i)) solve(best[s], best[s ^ (1 << i)]);
    for (int i = 1; i <= n + 1; ++i) {
      int s = Maxn ^ a[i];
      if (best[s][0].x == -1) continue;
      int p = find(i);
      if (best[s][0].p != p && (best[s][0].x ^ a[i]) > Max[p].x)
        Max[p] = best[s][0], Max[p].x ^= a[i];
      if (best[s][1].p != p && (best[s][1].x ^ a[i]) > Max[p].x)
        Max[p] = best[s][1], Max[p].x ^= a[i];
    }
    for (int i = 1; i <= n + 1; ++i) {
      int x = find(i), y = find(Max[i].p);
      if (x == i && x != y && (~Max[i].x)) {
        if (siz[x] > siz[y]) swap(x, y);
        f[x] = y, siz[y] += siz[x];
        tot--, ans += Max[i].x;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}