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 optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
using namespace std;
template <typename T>
void uin(T &a, T b) {
  if (b < a) {
    a = b;
  }
}
template <typename T>
void uax(T &a, T b) {
  if (b > a) {
    a = b;
  }
}
const long long N = 200 * 1000 + 228;
long long p[N], sz[N];
void init(long long n) {
  for (long long i = 0; i <= n; ++i) {
    p[i] = i;
    sz[i] = 1;
  }
}
long long getp(long long v) {
  if (v == p[v]) return v;
  p[v] = getp(p[v]);
  return p[v];
}
void join(long long u, long long v) {
  u = getp(u);
  v = getp(v);
  if (u != v) {
    if (sz[u] > sz[v]) swap(u, v);
    p[u] = v;
    sz[v] += sz[u];
  }
}
long long a[N];
long long color[N];
vector<long long> dp[2 * N], list228[2 * N];
vector<long long> g[N];
void dfs(long long v, long long col) {
  color[v] = col;
  for (long long to : g[v]) {
    if (!color[to]) dfs(to, col);
  }
}
void update(long long v, long long x) {
  bool found = 0;
  for (long long i = 0; i < (long long)dp[v].size(); ++i) {
    if (color[dp[v][i]] == color[x]) {
      if (a[x] > a[dp[v][i]]) dp[v][i] = x;
      found = 1;
    }
  }
  if (!found) dp[v].emplace_back(x);
  sort(dp[v].begin(), dp[v].end(),
       [&](long long i, long long j) { return a[i] > a[j]; });
  if (dp[v].size() > 2) dp[v].pop_back();
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  long long mx = 0;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    uax(mx, a[i]);
  }
  ++n;
  long long ss = 1;
  long long lg = 0;
  while (ss <= mx) ss <<= 1, ++lg;
  init(n);
  long long full = (1 << lg) - 1;
  long long answer = 0;
  while (1) {
    memset(color, 0, sizeof color);
    for (long long i = 0; i < ss; ++i) {
      dp[i].clear();
    }
    long long ptr = 0;
    for (long long i = 0; i < n; ++i) {
      list228[i].clear();
      if (!color[i]) {
        dfs(i, ++ptr);
      }
    }
    if (ptr == 1) break;
    for (long long i = 0; i < n; ++i) {
      list228[color[i]].emplace_back(i);
    }
    for (long long i = 0; i < n; ++i) {
      update(a[i], i);
    }
    for (long long i = 0; i < lg; ++i) {
      for (long long mask = 0; mask < (1 << lg); ++mask) {
        if ((mask >> i) & 1) {
          for (auto x : dp[mask ^ (1 << i)]) {
            update(mask, x);
          }
        }
      }
    }
    for (long long col = 1; col <= ptr; ++col) {
      long long to = -1, from = -1;
      long long value = -1;
      for (long long x : list228[col]) {
        for (long long y : dp[full ^ a[x]]) {
          if (color[x] != color[y] && a[x] + a[y] > value) {
            value = a[x] + a[y];
            from = x;
            to = y;
          }
        }
      }
      if (getp(from) != getp(to)) {
        g[from].emplace_back(to);
        g[to].emplace_back(from);
        join(to, from);
        answer += (a[from] + a[to]);
      }
    }
  }
  for (long long i = 0; i < n; ++i) {
    answer -= a[i];
  }
  cout << answer << '\n';
  return 0;
}