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;
template <typename _T>
inline void read(_T &f) {
  f = 0;
  _T fu = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') {
      fu = -1;
    }
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    f = (f << 3) + (f << 1) + (c & 15);
    c = getchar();
  }
  f *= fu;
}
template <typename T>
void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x < 10)
    putchar(x + 48);
  else
    print(x / 10), putchar(x % 10 + 48);
}
template <typename T>
void print(T x, char t) {
  print(x);
  putchar(t);
}
const int N = 2e5 + 5;
int mx[1 << 18][2], id[1 << 18][2];
int f[N], a[N], maxn[N], go[N];
int n, blocks;
long long ans;
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void add(int x, int y, int z) {
  if (y > mx[x][0]) {
    if (z != id[x][0]) {
      mx[x][1] = mx[x][0];
      id[x][1] = id[x][0];
    }
    mx[x][0] = y;
    id[x][0] = z;
  } else if (y > mx[x][1] && z != id[x][0]) {
    mx[x][1] = y;
    id[x][1] = z;
  }
}
int main() {
  read(n);
  blocks = n + 1;
  for (int i = 1; i <= n; i++) read(a[i]), f[i] = i, ans -= a[i];
  a[++n] = 0;
  f[n + 1] = n + 1;
  while (blocks > 1) {
    for (int i = 0; i < (1 << 18); i++) mx[i][0] = mx[i][1] = -1;
    for (int i = 1; i <= n; i++) add(a[i], a[i], find(i));
    for (int mid = 1; mid < (1 << 18); mid <<= 1) {
      for (int i = 0; i < (1 << 18); i += (mid << 1)) {
        for (int j = 0; j < mid; j++) {
          if (mx[i + j][0] != -1) add(i + j + mid, mx[i + j][0], id[i + j][0]);
          if (mx[i + j][1] != -1) add(i + j + mid, mx[i + j][1], id[i + j][1]);
        }
      }
    }
    memset(maxn, -1, sizeof(maxn));
    for (int i = 1; i <= n; i++) {
      int cat = ((1 << 18) - 1) ^ a[i];
      if (mx[cat][0] != -1 && id[cat][0] != find(i)) {
        if (mx[cat][0] + a[i] > maxn[find(i)]) {
          maxn[find(i)] = mx[cat][0] + a[i];
          go[find(i)] = id[cat][0];
        }
      }
      if (mx[cat][1] != -1 && id[cat][1] != find(i)) {
        if (mx[cat][1] + a[i] > maxn[find(i)]) {
          maxn[find(i)] = mx[cat][1] + a[i];
          go[find(i)] = id[cat][1];
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      if (find(i) == i) {
        if (find(i) != find(go[i])) {
          f[i] = go[i];
          ans += maxn[i];
          --blocks;
        }
      }
    }
  }
  print(ans, '\n');
  return 0;
}