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;
void solve();
using ll = long long;
template <class T = ll>
using V = vector<T>;
using vi = V<int>;
using vl = V<>;
using vvi = V<V<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {
  IoSetupNya() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(7);
  }
} iosetupnya;
template <typename T, typename U>
inline bool amin(T &x, U y) {
  return (y < x) ? (x = y, true) : false;
}
template <typename T, typename U>
inline bool amax(T &x, U y) {
  return (x < y) ? (x = y, true) : false;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  int s = (int)v.size();
  for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i];
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}
void in() {}
template <typename T, class... U>
void in(T &t, U &...u) {
  cin >> t;
  in(u...);
}
void out() { cout << "\n"; }
template <typename T, class... U>
void out(const T &t, const U &...u) {
  cout << t;
  if (sizeof...(u)) cout << " ";
  out(u...);
}
template <typename T>
void die(T x) {
  out(x);
  exit(0);
}
int main() { solve(); }
using vd = V<double>;
using vs = V<string>;
using vvl = V<V<> >;
template <typename T, typename U>
ll ceil(T a, U b) {
  return (a + b - 1) / b;
}
using P = pair<int, int>;
using vp = V<P>;
constexpr int MOD = 1000000007;
struct UnionFindTree {
  vi par, cnt;
  UnionFindTree(int N) : par(N, -1), cnt(N, 0) {}
  int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
  int unite(int x, int y) {
    if ((x = find(x)) == (y = find(y))) return 0;
    if (par[x] > par[y]) swap(x, y);
    int ans = (par[x] == -1 ? cnt[x] : 1) + (par[y] == -1 ? cnt[y] : 1) - 1;
    par[x] += par[y];
    par[y] = x;
    return ans;
  }
};
void solve() {
  int N;
  in(N);
  UnionFindTree uf(1 << 18);
  ll ans = 0;
  for (int i = 0; i < (int)(N); i++) {
    int a;
    in(a);
    uf.cnt[a]++;
    ans -= a;
  }
  uf.cnt[0]++;
  for (int i = (1 << 18) - 1; i >= 0; i--)
    for (int j = i; j > 0; j = (j - 1) & i) {
      int k = i ^ j;
      if (k >= j) break;
      if (uf.cnt[j] > 0 && uf.cnt[k] > 0) ans += 1LL * i * uf.unite(j, k);
    }
  out(ans);
}