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;
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
  out << '(' << p.first << ',' << p.second << ')';
  return out;
}
template <class T1, class T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
template <class T>
istream& operator>>(istream& in, vector<T>& v) {
  for (T& x : v) in >> x;
  return in;
}
template <class T>
ostream& operator<<(ostream& out, vector<vector<T>>& v) {
  for (vector<T>& x : v) out << x << '\n';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  for (T& x : v) out << x << ' ';
  return out;
}
long long gcd(long long a, long long b) {
  if (b > a) swap(a, b);
  return (b ? gcd(b, a % b) : a);
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
const int h = 1000000007;
ll ans = 0;
vi people_count(1 << 18);
class Dsu {
 private:
  vector<int> par, size;
  int distinct_sets_count;
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

 public:
  Dsu(int n) {
    distinct_sets_count = n;
    par.resize(n);
    for (int i = 0; i < n; i++) par[i] = i;
    size.resize(n, 1);
  }
  void unn(int a, int b) {
    int x = a, y = b;
    a = root(a), b = root(b);
    if (a == b) return;
    if (size[a] < size[b]) swap(a, b);
    ll num_connnections = (size[a] == 1 ? people_count[a] : 1) +
                          (size[b] == 1 ? people_count[b] : 1) - 1;
    size[a] += size[b];
    par[b] = a;
    ans += num_connnections * (x + y);
    distinct_sets_count--;
  }
  int set_count() { return distinct_sets_count; }
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.setstate(ios::failbit);
  int n;
  cin >> n;
  vi v(n);
  cin >> v;
  people_count[0]++;
  for (int x : v) people_count[x]++;
  int all_set_mask = (1 << 18) - 1;
  Dsu dsu(1 << 18);
  for (int sum = (1 << 18) - 1; sum > -1; sum--) {
    for (int x = sum; x; x = (x - 1) & sum) {
      int y = sum ^ x;
      if (people_count[x] and people_count[y]) dsu.unn(x, y);
    }
  }
  for (int i = 0; i < (1 << 18); i++) ans -= ll(i) * people_count[i];
  cout << ans;
}