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;
int n, f[200005], v[200005], cnt, to[200005];
inline int find(int x) {
  if (x == -1) return -1;
  return f[x] == x ? x : f[x] = find(f[x]);
}
pair<int, int> F[200005 * 2], G[200005 * 2], mx[200005];
void add(int p, int a, int c) {
  if (a > F[p].first) {
    if (c != F[p].second) G[p] = F[p];
    F[p] = make_pair(a, c);
  } else if (a > G[p].first && c != F[p].second)
    G[p] = make_pair(a, c);
}
int main() {
  scanf("%d", &n);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &v[i]);
    f[i] = i;
    ans -= v[i];
  }
  v[++n] = 0;
  f[n] = n;
  int zt = 1 << 18;
  --zt;
  while (cnt < n - 1) {
    memset(F, -1, sizeof F);
    memset(G, -1, sizeof G);
    memset(mx, -1, sizeof mx);
    for (int i = 1; i <= n; ++i) {
      f[i] = find(f[i]);
      add(v[i], v[i], f[i]);
    }
    for (int i = 1; i <= zt; ++i) {
      for (int jj = 1; jj <= zt; jj <<= 1) {
        if ((i & jj) && F[i ^ jj].first != -1) {
          add(i, F[i ^ jj].first, F[i ^ jj].second);
          add(i, G[i ^ jj].first, G[i ^ jj].second);
        }
      }
      add(i, F[0].first, F[0].second);
      add(i, G[0].first, G[0].second);
    }
    pair<int, int> hc;
    for (int i = 1; i <= n; ++i) {
      if (F[v[i] ^ zt].second != f[i])
        hc = F[v[i] ^ zt];
      else
        hc = G[v[i] ^ zt];
      hc.first += v[i];
      if (hc.first > mx[f[i]].first) mx[f[i]] = hc;
    }
    for (int a, b, i = 1; i <= n; ++i) {
      a = find(i), b = find(mx[f[i]].second);
      if (b == -1) continue;
      if (a != b) {
        ans += mx[f[i]].first;
        f[a] = b;
        ++cnt;
      }
    }
  }
  printf("%lld", ans);
  return 0;
}