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 = 1e6 + 7;
bool fl[N];
int n, m, tot, w[N], f[N], g1[N], g2[N], f1[N], f2[N];
struct edg {
  int u, v, w;
} e[N];
inline int read() {
  int num = 0;
  char g = getchar();
  while (g < 48 || 57 < g) g = getchar();
  while (47 < g && g < 58) num = num * 10 + g - 48, g = getchar();
  return num;
}
inline int find(int u) {
  if (f[u] == u) return u;
  return f[u] = find(f[u]);
}
inline void adds(int u, int c, int p) {
  if (g1[u] == find(p))
    f1[u] = max(f1[u], c);
  else if (c > f1[u])
    f2[u] = f1[u], g2[u] = g1[u], f1[u] = c, g1[u] = find(p);
  else if (g1[u] == 0)
    f2[u] = f1[u], g2[u] = g1[u], f1[u] = c, g1[u] = find(p);
  else if (c > f2[u])
    f2[u] = c, g2[u] = find(p);
  else if (g2[u] == 0)
    f2[u] = c, g2[u] = find(p);
}
inline bool cmp(edg a, edg b) { return a.w > b.w; }
int main() {
  n = read(), m = 262143;
  long long ans = 0;
  for (int i = 1; i <= n; i++) w[i] = read(), f[i] = i, ans -= w[i];
  n++, f[n] = n;
  for (int i = 1; i <= 20; i++) {
    memset(g1, 0, sizeof(g1)), memset(g2, 0, sizeof(g2));
    memset(f1, 0, sizeof(f1)), memset(f2, 0, sizeof(f2));
    memset(fl, 0, sizeof(fl)), tot = 0;
    for (int x = 1; x <= n; x++) adds(w[x], w[x], x);
    for (int x = 0; x <= m; x++)
      for (int z = 0; z < 18; z++)
        if ((1 << z) & x)
          adds(x, f1[x - (1 << z)], g1[x - (1 << z)]),
              adds(x, f2[x - (1 << z)], g2[x - (1 << z)]);
    for (int x = 1; x <= n; x++) {
      if (find(g1[w[x] ^ m]) == find(x)) {
        if (g2[w[x] ^ m])
          tot++, e[tot].u = find(x), e[tot].v = g2[w[x] ^ m],
                 e[tot].w = f2[w[x] ^ m] + w[x];
      } else {
        tot++, e[tot].u = find(x), e[tot].v = g1[w[x] ^ m],
               e[tot].w = f1[w[x] ^ m] + w[x];
      }
    }
    sort(e + 1, e + tot + 1, cmp);
    for (int i = 1; i <= tot; i++)
      if (!fl[find(e[i].u)])
        ans += e[i].w, f[find(e[i].u)] = find(e[i].v), fl[find(e[i].u)] = 1;
  }
  cout << ans << endl;
  return 0;
}