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 N = (1 << 18);
int p[N];
int s[N];
int init(int n) {
  iota(p, p + n, 0);
  fill(s, s + n, 1);
  return 1;
}
int lead(int x) { return p[x] == x ? x : p[x] = lead(p[x]); }
int join(int x, int y) {
  x = lead(x);
  y = lead(y);
  if (x == y) return 0;
  if (s[x] < s[y]) swap(x, y);
  p[y] = x;
  s[x] += s[y];
  return 1;
}
int arr[N];
pair<int, int> opt[N][2];
pair<int, pair<int, int> > best[N];
void upd(int x, pair<int, int> F) {
  if (opt[x][0] < F && F.second != opt[x][1].second) opt[x][0] = F;
  if (opt[x][1] < opt[x][0]) swap(opt[x][0], opt[x][1]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    ans -= arr[i];
  }
  init(++n);
  int numTrees = n;
  while (numTrees > 1) {
    for (int i = 0; i < N; ++i)
      opt[i][0] = pair<int, int>(-1, -1), opt[i][1] = pair<int, int>(-1, -1);
    for (int i = 0; i < n; ++i)
      upd(arr[i], pair<int, int>(arr[i], lead(i))),
          best[i] = pair<int, pair<int, int> >(-1, pair<int, int>(i, i));
    for (int i = 0; i < 18; ++i)
      for (int j = 0; j < N; ++j)
        if (j >> i & 1)
          upd(j, opt[j ^ (1 << i)][0]), upd(j, opt[j ^ (1 << i)][1]);
    for (int i = 0; i < n; ++i) {
      int x = (1 << 18) - 1 - arr[i];
      pair<int, int> F = pair<int, int>(-1, -1);
      if (opt[x][1].second != lead(i))
        F = opt[x][1];
      else
        F = opt[x][0];
      if (F.second >= 0) {
        int nxt = arr[i] + F.first;
        pair<int, pair<int, int> >& val = best[lead(i)];
        if (val.first < nxt) {
          val.first = nxt;
          val.second = pair<int, int>(i, F.second);
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      int u = best[i].second.first;
      int v = best[i].second.second;
      if (join(u, v)) ans += best[i].first, numTrees--;
    }
  }
  cout << ans << endl;
}