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 MOD = (int)1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int)1e9 + 23111992;
const long long LINF = (long long)1e18 + 23111992;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline unsigned long long isqrt(unsigned long long k) {
  unsigned long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() { return abs((int)mt()); }
void chemthan() {
  int n;
  cin >> n;
  vector<int> f(1 << 18);
  int mx = 0;
  for (int i = (0); i < (n); ++i) {
    int x;
    cin >> x;
    f[x]++;
    chkmax(mx, x);
  }
  long long res = 0;
  for (int u = (0); u < (1 << 18); ++u)
    if (f[u]) {
      int pu = u ^ (1 << 18) - 1;
      for (int v = pu;; v = v - 1 & pu) {
        if (f[v]) {
          res += (long long)v * (f[u] - 1);
          break;
        }
        if (!v) break;
      }
    }
  vector<int> a(1 << 18);
  vector<int> b(1 << 18);
  priority_queue<int> g;
  vector<vector<int> > ss(1 << 19);
  for (int i = (0); i < (1 << 18); ++i)
    if (f[i]) {
      ss[a[i] = i].push_back(i);
      if (int((ss[a[i]]).size()) == 1) {
        g.push(a[i]);
      }
    }
  while (int((g).size())) {
    int t = g.top();
    if (int((ss[t]).size()) == 1) {
      g.pop();
    }
    if (int((ss[t]).size())) {
      int u = ss[t].back();
      ss[t].pop_back();
      if (a[u] == t) {
        res += b[u];
        f[u] = 0;
        int pu = u ^ (1 << 18) - 1;
        for (int v = pu;; v = v - 1 & pu) {
          if (f[v]) {
            if (chkmax(b[v], u)) {
              a[v] = v + b[v];
              ss[a[v]].push_back(v);
              if (int((ss[a[v]]).size()) == 1) {
                g.push(a[v]);
              }
            }
          }
          if (!v) break;
        }
      }
    }
  }
  cout << res << "\n";
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  chemthan();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}