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")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
using namespace std;
clock_t time_p = clock();
void aryanc403() {}
const long long int INF = 0xFFFFFFFFFFFFFFFL;
long long int seed;
mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count());
inline long long int rnd(long long int l = 0, long long int r = INF) {
  return uniform_int_distribution<long long int>(l, r)(rng);
}
class CMP {
 public:
  bool operator()(pair<long long int, long long int> a,
                  pair<long long int, long long int> b) {
    return !(a.first < b.first || (a.first == b.first && a.second <= b.second));
  }
};
void add(map<long long int, long long int> &m, long long int x,
         long long int cnt = 1) {
  auto jt = m.find(x);
  if (jt == m.end())
    m.insert({x, cnt});
  else
    jt->second += cnt;
}
void del(map<long long int, long long int> &m, long long int x,
         long long int cnt = 1) {
  auto jt = m.find(x);
  if (jt->second <= cnt)
    m.erase(jt);
  else
    jt->second -= cnt;
}
bool cmp(const pair<long long int, long long int> &a,
         const pair<long long int, long long int> &b) {
  return a.first < b.first || (a.first == b.first && a.second < b.second);
}
const long long int mod = 1000000007L;
const long long int L = 18L;
const long long int M = (1LL << L) - 1;
long long int T, n, i, j, k, in, cnt, l, r, u, v, x, y;
long long int m;
string s;
vector<long long int> a, b;
int mx[M + 5];
bitset<M + 1> vis;
int id[M + 1];
int getRoot(int n) {
  if (id[n] == n) return n;
  return id[n] = getRoot(id[n]);
}
bool join(int u, int v) {
  u = getRoot(u);
  v = getRoot(v);
  id[u] = v;
  return u != v;
}
long long int mxcomp(const vector<long long int> &b) {
  for (int i = 1; i <= M; ++i)
    for (int j = 0; j < L; ++j)
      if (i & (1 << j)) mx[i] = max(mx[i], mx[i ^ (1 << j)]);
  long long int ans = 0;
  for (auto x : b) ans += mx[M ^ x];
  return ans;
}
long long int solve() {
  long long int ans = 0;
  for (int k = M; k >= 0; --k)
    for (int j = k; j > k - j; j = (j - 1) & k)
      if (vis[j] && vis[k - j] && join(k - j, j)) ans += k;
  return ans;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  {
    cin >> n;
    iota(id, id + M + 1, 0);
    ;
    long long int ans = 0;
    vis[0] = 1;
    for (i = 0; i < (n); ++i) {
      cin >> in;
      if (vis[in])
        b.push_back(in);
      else {
        vis[in] = 1;
        mx[in] = in;
        ans -= in;
      }
    }
    ans += mxcomp(b);
    ans += solve();
    cout << ans << "\n";
  }
  aryanc403();
  return 0;
}