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")
using namespace std;
using i64 = long long;
using i32 = int;
using f64 = long double;
template <class Key>
using vec = vector<Key>;
template <class Key>
using heap = priority_queue<Key>;
template <class Key>
using hash_set = unordered_set<Key>;
template <class Key, class Value>
using hash_map = unordered_map<Key, Value>;
using str = string;
using p64 = pair<i32, i32>;
using v64 = vec<i32>;
using vv64 = vec<v64>;
using s64 = set<i32>;
using m64 = map<i32, i32>;
const i32 inf = numeric_limits<i32>::max() / 2;
template <typename T>
inline i64 sz(const T& a) {
  return (i64)(a.size());
}
inline void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
template <typename T>
inline bool check_min(T& a, T b) {
  if (a > b) return a = b, 1;
  return 0;
}
template <typename T>
inline bool check_max(T& a, T b) {
  if (a < b) return a = b, 1;
  return 0;
}
struct Problem {
  Problem(bool multitest = 0) {
    read();
    if (!multitest) solve();
  }
  void solve(), read();
};
signed main() {
  fast();
  Problem();
  return 0;
}
struct Dsu {
  i32 n;
  v64 t, sz;
  v64 used;
  Dsu() {}
  Dsu(i32 n_) {
    n = n_;
    t.resize(n);
    iota((t).begin(), (t).end(), 0);
    sz.resize(n, 1);
    used.resize(n, 0);
  }
  i32 find(i32 v) {
    if (v == t[v]) return v;
    return t[v] = find(t[v]);
  }
  i32 join(i32 v, i32 u) {
    used[v] = used[u] = 1;
    v = find(v), u = find(u);
    if (v == u) return 0;
    if (sz[v] > sz[u]) swap(v, u);
    t[v] = u;
    sz[u] += sz[v];
    return 1;
  }
};
const i32 MAXN = 2e5 + 1;
const i32 LOG = 18;
i32 n;
v64 a;
Dsu d;
i64 bs[1 << LOG];
i64 ind[1 << LOG];
void Problem::solve() {
  d = Dsu(n + 1);
  i64 ans = 0;
  for (i32 sum = (1 << LOG) - 1; sum >= 0; sum--) {
    for (i32 f = sum; f > 0; f = sum & (f - 1)) {
      i32 s = sum ^ f;
      if (!bs[f]) continue;
      if (!bs[s]) continue;
      i32 cnt1 = bs[f];
      i32 cnt2 = bs[s];
      if (d.used[ind[f]]) cnt1 = 1;
      if (d.used[ind[s]]) cnt2 = 1;
      if (d.join(ind[f], ind[s])) {
        ans += sum * 1ll * (cnt1 + cnt2 - 1);
      }
    }
  }
  for (i32 i = 0; i < n; i++) {
    ans -= a[i];
  }
  cout << ans << "\n";
}
void Problem::read() {
  cin >> n;
  a.resize(n);
  for (i32 i = 0; i < n; i++) {
    cin >> a[i];
    ++bs[a[i]];
    ind[a[i]] = i;
  }
  a.push_back(0);
  ++bs[0];
  ind[0] = n;
}