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 G>
struct triple {
  G first, second, T;
  triple(G x, G y, G z) : first(x), second(y), T(z) {}
  triple() : first(0), second(0), T(0) {}
};
vector<int> v;
vector<int> p;
struct mx {
  int a, b;
  mx() : a(-1), b(-1) {}
  void push(int c) {
    if (c == -1) return;
    if (a == -1 || v[a] < v[c]) {
      if (a == -1 || p[a] != p[c]) swap(a, b);
      a = c;
    } else if ((b == -1 || v[b] < v[c]) && p[a] != p[c])
      b = c;
  }
  int query(int x) {
    if (a != -1 && p[a] != p[x]) return a;
    if (b != -1 && p[b] != p[x]) return b;
    return -1;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  const int LOG = 18;
  int n;
  cin >> n;
  v = vector<int>(n);
  for (auto &i : v) cin >> i;
  v.push_back(0);
  ++n;
  int comp = n;
  vector<vector<int>> cmp(n);
  p = vector<int>(n);
  vector<pair<int, int>> ex(n);
  vector<mx> dp(1 << LOG);
  for (int i = 0; i < n; i++) {
    cmp[i].push_back(i);
    p[i] = i;
  }
  long long ans = 0;
  while (comp > 1) {
    for (auto &i : cmp)
      for (auto &j : i) dp[v[j]].push(j);
    for (int i = 0; i < LOG; i++)
      for (int j = 0; j < (1 << LOG); j++)
        if (j >> i & 1) {
          int mask = j ^ (1 << i);
          dp[j].push(dp[mask].a);
          dp[j].push(dp[mask].b);
        }
    for (int i = 0; i < n; i++)
      for (auto &j : cmp[i]) {
        int temp = dp[((1 << LOG) - 1) ^ v[j]].query(j);
        if (temp != -1 && v[j] + v[temp] >= ex[i].first) {
          ex[i].first = v[j] + v[temp];
          ex[i].second = temp;
        }
      }
    for (int i = 0; i < n; i++)
      if (ex[i].second != -1) {
        int x = p[ex[i].second];
        int y = p[i];
        if (x != y) {
          --comp;
          ans += ex[i].first;
          if (cmp[x].size() > cmp[y].size()) swap(x, y);
          for (auto &j : cmp[x]) {
            p[j] = y;
            cmp[y].push_back(j);
          }
          cmp[x].clear();
        }
      }
    for (int i = 0; i < n; i++) ex[i].first = ex[i].second = -1;
    for (int i = 0; i < (1 << LOG); i++) dp[i].a = dp[i].b = -1;
  }
  for (int i = 0; i < n; i++) ans -= v[i];
  cout << ans << '\n';
  return 0;
}