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 read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
  return f ? -x : x;
}
template <typename T>
void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void print(T x, char let) {
  print(x), putchar(let);
}
const int maxn = 2e5 + 5;
const int mn = (1 << 18) - 1;
int n, a[maxn], b[mn], f[mn], sz[mn];
int find(int k) {
  if (f[k] == k) return k;
  return f[k] = find(f[k]);
}
void merge(int a, int b) {
  int fa = find(a);
  int fb = find(b);
  if (sz[fa] <= sz[fb]) {
    f[fa] = fb;
    sz[fb] += sz[fa];
  } else {
    f[fb] = fa;
    sz[fa] += sz[fb];
  }
}
int main() {
  n = read();
  long long sum1 = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    sum1 += a[i];
    b[a[i]]++;
  }
  b[0]++;
  for (int i = 0; i <= mn; i++) f[i] = i;
  long long sum = 0;
  for (int i = mn; i >= 1; i--) {
    if (b[0] > 0 && b[i] > 0 && find(0) != find(i)) {
      merge(0, i);
      sum += (long long)(b[0] + b[i] - 1) * i;
      b[0] = b[i] = 1;
    }
    for (int j = i; j; j = (j - 1) & i) {
      int k = i ^ j;
      if (b[j] > 0 && b[k] > 0 && find(j) != find(k)) {
        merge(j, k);
        sum += (long long)(b[j] + b[k] - 1) * i;
        b[j] = b[k] = 1;
      }
    }
  }
  cout << sum - sum1 << endl;
  return 0;
}