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 = (1 << 18) + 7;
int n, m, L, a[N], fa[N], tot, f[N], g[N];
long long ans;
struct edge {
  int w, u, v;
  friend bool operator<(edge p, edge q) { return p.w < q.w; }
} w[N];
int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); }
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i], m = max(m, a[i]);
  ++n;
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (L = 1; (1 << L) <= m; ++L)
    ;
  m = (1 << L);
  tot = n;
  while (tot > 1) {
    memset(g, -1, m << 2);
    memset(f, -1, m << 2);
    for (int i = 1; i <= n; ++i) {
      int &x = f[a[i]];
      if (!~x)
        x = i;
      else if (getfa(x) != getfa(i))
        g[a[i]] = i;
    }
    for (int i = 1; i < m; ++i) {
      for (int j = 0; j < L; ++j)
        if (i >> j & 1) {
          int x = f[i ^ (1 << j)];
          if (!~x) continue;
          if (!~f[i]) {
            f[i] = x;
            continue;
          }
          if (getfa(x) != getfa(f[i])) {
            if (a[x] > a[f[i]])
              g[i] = f[i], f[i] = x;
            else if (!~g[i])
              g[i] = x;
            else if (a[x] > a[g[i]])
              g[i] = x;
          } else if (a[x] > a[f[i]])
            f[i] = x;
          x = g[i ^ (1 << j)];
          if (!~x) continue;
          if (getfa(x) != getfa(f[i])) {
            if (a[x] > a[f[i]])
              g[i] = f[i], f[i] = x;
            else if (!~g[i])
              g[i] = x;
            else if (a[x] > a[g[i]])
              g[i] = x;
          } else if (a[x] > a[f[i]])
            f[i] = x;
        }
    }
    for (int i = 1; i <= n; ++i) w[i] = (edge){-1, -1, -1};
    for (int i = 1, v; i <= n; ++i)
      if (~f[v = ((m - 1) ^ a[i])]) {
        int x = getfa(f[v]) == getfa(i) ? g[v] : f[v];
        if (!~x) continue;
        assert(!(a[x] & a[i]));
        assert(getfa(x) != getfa(i));
        w[getfa(i)] = max(w[getfa(i)], (edge){a[x] + a[i], i, x});
      }
    for (int i = 1; i <= n; ++i)
      if (getfa(i) == i) {
        int u = w[i].u, v = w[i].v;
        if (getfa(u) == getfa(v)) continue;
        --tot;
        ans += a[u] + a[v], fa[getfa(u)] = getfa(v);
      }
  }
  for (int i = 1; i <= n; ++i) ans -= a[i];
  cout << ans << endl;
  return 0;
}