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 RLEN = 1 << 20 | 1;
inline char gc() {
  static char ibuf[RLEN], *ib, *ob;
  (ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
  return (ib == ob) ? EOF : *ib++;
}
inline int read() {
  char ch = gc();
  int res = 0;
  bool f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = gc();
  while (isdigit(ch)) res = (res + (res << 2) << 1) + (ch ^ 48), ch = gc();
  return f ? res : -res;
}
inline long long readll() {
  char ch = gc();
  long long res = 0;
  bool f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = gc();
  while (isdigit(ch)) res = (res + (res << 2) << 1) + (ch ^ 48), ch = gc();
  return f ? res : -res;
}
inline int readstring(char *s) {
  int top = 0;
  char ch = gc();
  while (isspace(ch)) ch = gc();
  while (!isspace(ch) && ch != EOF) s[++top] = ch, ch = gc();
  return top;
}
template <class tp>
inline void chemx(tp &a, tp b) {
  a < b ? a = b : 0;
}
template <class tp>
inline void chemn(tp &a, tp b) {
  a > b ? a = b : 0;
}
const int mod = 1e9 + 7;
inline int add(int a, int b) { return (a += b) >= mod ? (a - mod) : a; }
inline int dec(int a, int b) {
  a -= b;
  return a + (a >> 31 & mod);
}
inline int mul(int a, int b) {
  static long long r;
  r = 1ll * a * b;
  return (r >= mod) ? (r % mod) : r;
}
inline void Add(int &a, int b) { (a += b) >= mod ? (a -= mod) : 0; }
inline void Dec(int &a, int b) { a -= b, a += a >> 31 & mod; }
inline void Mul(int &a, int b) {
  static long long r;
  r = 1ll * a * b;
  a = (r >= mod) ? (r % mod) : r;
}
inline int ksm(int a, int b, int res = 1) {
  if (a == 0 && b == 0) return 0;
  for (; b; b >>= 1, Mul(a, a)) (b & 1) && (Mul(res, a), 1);
  return res;
}
inline int Inv(int x) { return ksm(x, mod - 2); }
inline int fix(int x) { return (x < 0) ? x + mod : x; }
const int N = (1 << 18) + 5;
int fa[N], siz[N], cnt[N], n;
inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
inline int merge(int u, int v) {
  int f1 = find(u), f2 = find(v);
  if (f1 == f2) return 0;
  int res = (siz[f1] == 1 ? cnt[f1] : 1) + (siz[f2] == 1 ? cnt[f2] : 1) - 1;
  fa[f1] = f2, siz[f2] += siz[f1];
  return res;
}
int main() {
  n = read();
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    int x = read();
    res -= x;
    cnt[x]++;
  }
  cnt[0]++;
  for (int i = 0; i < (1 << 18); i++) fa[i] = i, siz[i] = 1;
  for (int i = (1 << 18) - 1; i; i--) {
    for (int s = i; s; s = (s - 1) & i) {
      if (s < (i ^ s)) break;
      if (cnt[s] && cnt[i ^ s]) res += 1ll * i * merge(s, i ^ s);
    }
  }
  cout << res;
  return 0;
}