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>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T>
T sqr(T a) {
  return a * a;
}
template <typename T>
int sign(T a) {
  if (a == 0) return 0;
  return (a > 0 ? 1 : -1);
}
template <typename T1, typename T2>
T2 sum_mod(T1 x, T2 MOD) {
  if (x < 0) x += MOD;
  if (x >= MOD) x -= MOD;
  return x;
}
template <typename T1, typename T2>
T2 mul_mod(T1 x, T2 MOD) {
  if (x < 0) return (abs(x) % MOD == 0 ? 0 : MOD - abs(x) % MOD);
  return x % MOD;
}
template <typename T>
bool uax(T& a, const T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool uin(T& a, const T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2>& p) {
  out << p.first << ' ' << p.second;
  return out;
}
mt19937_64 rnd;
const int LOG = 18;
const int N = (int)3e5 + 7;
const int MAXN = (int)6e4 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const int CONST = 300;
const long long LINF = (int64_t)2e15;
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1;
int sz[N], par[N];
int get_par(int u) {
  if (u == par[u]) return u;
  return par[u] = get_par(par[u]);
}
bool unite(int u, int v) {
  u = get_par(u), v = get_par(v);
  if (u == v) return false;
  if (sz[u] < sz[v]) swap(u, v);
  par[v] = u;
  sz[u] += sz[v];
  return true;
}
int n, a[N], comp[N];
pair<int, int> dp[1 << LOG][2], best[1 << LOG], buff[4];
void merge(pair<int, int>* a, pair<int, int>* b) {
  int i = 0, ia = 0, ib = 0;
  while (ia < 2 && ib < 2) {
    if (a[ia].first > b[ib].first) {
      buff[i] = a[ia];
      i++, ia++;
    } else {
      buff[i] = b[ib];
      i++, ib++;
    }
  }
  while (ia < 2) {
    buff[i] = a[ia];
    i++, ia++;
  }
  while (ib < 2) {
    buff[i] = a[ib];
    i++, ib++;
  }
  a[0] = buff[0];
  for (int i = 1; i < 4; i++) {
    if (a[0].second != buff[i].second) {
      a[1] = buff[i];
      break;
    }
  }
}
void calc_dp() {
  for (int i = 0; i < (1 << LOG); i++) dp[i][0] = dp[i][1] = make_pair(-1, -1);
  pair<int, int> upd[2];
  for (int i = 0; i <= n; i++) {
    upd[0] = make_pair(a[i], comp[i]);
    upd[1] = make_pair(-1, -1);
    merge(dp[a[i]], upd);
  }
  for (int bit = 0; bit < LOG; bit++) {
    for (int mask = 0; mask < (1 << LOG); mask++) {
      if ((mask & (1 << bit)) == 0) continue;
      merge(dp[mask], dp[mask ^ (1 << bit)]);
    }
  }
}
int main() {
  double start = clock();
  cout << fixed << setprecision(20);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  rnd.seed(time(0));
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ans -= a[i];
  }
  for (int i = 0; i <= n; i++) sz[i] = 1, par[i] = comp[i] = i;
  int cmp = n + 1, full = (1 << LOG) - 1;
  while (cmp > 1) {
    calc_dp();
    fill(best, best + n + 1, make_pair(-1, -1));
    for (int i = 0; i <= n; i++) {
      int mask = full ^ a[i];
      pair<int, int> curb = make_pair(-1, -1);
      if (comp[i] == dp[mask][0].second)
        curb = dp[mask][1];
      else
        curb = dp[mask][0];
      curb.first += a[i];
      if (curb.second == -1) continue;
      uax(best[comp[i]], curb);
    }
    bool fl = false;
    for (int i = 0; i <= n; i++) {
      int u = comp[i], v = best[u].second;
      if (unite(u, v)) {
        ans += best[u].first;
        cmp--;
        fl = true;
      }
    }
    assert(fl);
    for (int i = 0; i <= n; i++) comp[i] = get_par(i);
  }
  cout << ans;
}