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 maxn = 2e5 + 5;
struct data {
  pair<long long, int> ma1, ma2;
  void init(void) { ma1 = ma2 = make_pair(-1e18, -1); }
  void add(pair<long long, int> val) {
    if (ma1.first < val.first) {
      swap(ma1, val);
    }
    if (ma2.first < val.first) {
      if (val.second != ma1.second) swap(ma2, val);
    }
  }
} f[(1 << 18)];
int N, a[maxn], lab[maxn];
long long mst = 0;
pair<long long, int> best[maxn];
int finds(int u) {
  if (lab[u] < 0) return u;
  return lab[u] = finds(lab[u]);
}
bool merges(int u, int v) {
  u = finds(u), v = finds(v);
  if (u == v) return false;
  if (lab[v] < lab[u]) swap(u, v);
  lab[u] += lab[v];
  lab[v] = u;
  return true;
}
signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> a[i];
    mst -= a[i];
  }
  for (int i = 0; i <= N; ++i) lab[i] = -1;
  int cnt = N;
  while (cnt) {
    for (int i = 0; i <= N; ++i) best[i] = make_pair(-1e18, -1);
    for (int i = 0; i < (1 << 18); ++i) f[i].init();
    for (int i = 0; i <= N; ++i) f[a[i]].add(make_pair(a[i], finds(i)));
    for (int b = 0; b < 18; ++b) {
      for (int mask = 0; mask < (1 << 18); ++mask) {
        if (mask >> b & 1) {
          f[mask].add(f[mask ^ (1 << b)].ma1);
          f[mask].add(f[mask ^ (1 << b)].ma2);
        }
      }
    }
    for (int i = 0; i <= N; ++i) {
      int tmp = finds(i);
      int req = ((1 << 18) - 1 - a[i]);
      if (tmp != f[req].ma1.second)
        best[tmp] = max(best[tmp],
                        make_pair(f[req].ma1.first + a[i], f[req].ma1.second));
      if (tmp != f[req].ma2.second)
        best[tmp] = max(best[tmp],
                        make_pair(f[req].ma2.first + a[i], f[req].ma2.second));
    }
    for (int i = 0; i <= N; ++i) {
      if (lab[i] < 0 && best[i].second != -1) {
        if (merges(i, best[i].second)) {
          --cnt;
          mst += best[i].first;
        }
      }
    }
  }
  cout << mst;
}