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;
using LL = long long;
template <class T>
inline bool asMn(T &a, const T &b) {
  return a > b ? a = b, true : false;
}
template <class T>
inline bool asMx(T &a, const T &b) {
  return a < b ? a = b, true : false;
}
const int NBit = 18, All = (1 << NBit) - 1;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
struct Dsu {
  int nSet;
  vector<int> pSet;
  Dsu(int _nSet) : nSet(_nSet) {
    pSet.assign(nSet, 0);
    iota((pSet).begin(), (pSet).end(), 0);
  }
  int findSet(int i) { return i ^ pSet[i] ? pSet[i] = findSet(pSet[i]) : i; }
  bool unite(int i, int j) {
    i = findSet(i);
    j = findSet(j);
    if (i == j) return false;
    --nSet;
    pSet[i] = j;
    return true;
  }
};
void ins(pair<int, int> v, array<pair<int, int>, 2> &mx) {
  if (all_of((mx).begin(), (mx).end(),
             [&](pair<int, int> i) { return i.second ^ v.second; })) {
    for (int i = 0; i < 2; ++i)
      if (mx[i] < v) swap(mx[i], v);
  } else {
    for (int i = 0; i < 2; ++i)
      if (mx[i].second == v.second) {
        asMx(mx[i], v);
        break;
      }
    if (mx[0] < mx[1]) swap(mx[0], mx[1]);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  a.emplace_back(0);
  Dsu dsu(((int)(a).size()));
  LL ans = -accumulate((a).begin(), (a).end(), 0LL);
  vector<array<pair<int, int>, 2> > subset(1 << NBit);
  vector<pair<int, int> > d(((int)(a).size()));
  while (dsu.nSet ^ 1) {
    fill((subset).begin(), (subset).end(),
         array<pair<int, int>, 2>{make_pair(-1, -1), make_pair(-1, -1)});
    for (int i = 0; i < ((int)(a).size()); ++i)
      ins(make_pair(a[i], dsu.findSet(i)), subset[a[i]]);
    for (int i = 0; i < NBit; ++i) {
      for (int mask = 0; mask < 1 << NBit; ++mask)
        if ((mask >> i) & 1) {
          for (const auto &j : subset[mask ^ (1 << i)]) ins(j, subset[mask]);
        }
    }
    fill((d).begin(), (d).end(), make_pair(-1, -1));
    for (int i = 0; i < ((int)(a).size()); ++i) {
      int p = dsu.findSet(i), mask = a[i] ^ All;
      for (const auto &j : subset[mask])
        if (p ^ j.second && ~j.second)
          asMx(d[p], make_pair(a[i] + j.first, j.second));
    }
    for (int i = 0; i < ((int)(d).size()); ++i)
      if (dsu.findSet(i) == i && dsu.unite(i, d[i].second)) ans += d[i].first;
  }
  cout << ans << '\n';
  return 0;
}