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 P = 1e9 + 7, INF = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long n) {
  long long r = 1 % P;
  for (a %= P; n; a = a * a % P, n >>= 1)
    if (n & 1) r = r * a % P;
  return r;
}
long long inv(long long first) {
  return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;
}
inline int rd() {
  int first = 0;
  char p = getchar();
  while (p < '0' || p > '9') p = getchar();
  while (p >= '0' && p <= '9') first = first * 10 + p - '0', p = getchar();
  return first;
}
const int N = 1e6 + 50;
int n, a[N], fa[N];
pair<int, int> g[N];
struct {
  void add(int id, int v) {
    if (a[0].second == id)
      a[0].first = max(a[0].first, v);
    else if (a[1].first < v)
      a[1] = {v, id};
    if (a[0].first < a[1].first) swap(a[0], a[1]);
  }
  void add(pair<int, int> u) { add(u.second, u.first); }
  pair<int, int> ask(int id) {
    if (a[0].second != id) return a[0];
    return a[1];
  }
  pair<int, int> a[2] = {{-1, 0}, {-1, 0}};
} f[1 << 18];
int Find(int first) { return fa[first] ? fa[first] = Find(fa[first]) : first; }
int main() {
  scanf("%d", &n);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) scanf("%d", a + i), ans -= a[i];
  a[++n] = 0;
  int cnt = n, mx = (1 << 18) - 1;
  while (cnt > 1) {
    for (int i = 0; i <= mx; ++i) f[i] = {};
    for (int i = 1; i <= n; ++i) f[a[i]].add(Find(i), a[i]);
    for (int i = 0; i <= 17; ++i)
      for (int j = 0; j <= mx; ++j)
        if (j >> i & 1) {
          f[j].add(f[j ^ (1 << i)].a[0]);
          f[j].add(f[j ^ (1 << i)].a[1]);
        }
    for (int i = 1; i <= n; ++i) g[i] = {-1, 0};
    for (int i = 1; i <= n; ++i) {
      int u = Find(i);
      auto t = f[mx ^ a[i]].ask(u);
      t.first += a[i];
      if (t.second && t.first > g[u].first) g[u] = t;
    }
    for (int i = 1; i <= n; ++i)
      if (g[i].second) {
        int first = Find(i), second = Find(g[i].second);
        if (first != second) {
          fa[first] = second;
          --cnt, ans += g[i].first;
        }
      }
  }
  printf("%lld\n", ans);
}