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;
constexpr int maxn = 1 << 18;
struct IO {
 private:
  static constexpr int ibufsiz = 1 << 20;
  char ibuf[ibufsiz + 1], *inow = ibuf, *ied = ibuf;
  static constexpr int obufsiz = 1 << 20;
  char obuf[obufsiz + 1], *onow = obuf;
  const char *oed = obuf + obufsiz;

 public:
  char getchar() {
    if (inow == ied) {
      ied = ibuf + sizeof(char) * fread(ibuf, sizeof(char), ibufsiz, stdin);
      *ied = '\0';
      inow = ibuf;
    }
    return *inow++;
  }
  template <typename T>
  void read(T &x) {
    static bool flg;
    flg = 0;
    x = 0;
    char c = getchar();
    while (!isdigit(c)) flg = c == '-' ? 1 : flg, c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
    if (flg) x = -x;
  }
  template <typename T, typename... Y>
  void read(T &x, Y &...X) {
    read(x);
    read(X...);
  }
  int readi() {
    static int res;
    read(res);
    return res;
  }
  long long readll() {
    static long long res;
    read(res);
    return res;
  }
  void flush() {
    fwrite(obuf, sizeof(char), onow - obuf, stdout);
    fflush(stdout);
    onow = obuf;
  }
  void putchar(const char c) {
    *onow++ = c;
    if (onow == oed) {
      fwrite(obuf, sizeof(char), obufsiz, stdout);
      onow = obuf;
    }
  }
  template <typename T>
  void write(T x, const char split = '\0') {
    static unsigned char buf[32];
    if (x < 0) putchar('-'), x = -x;
    int p = 0;
    do {
      buf[++p] = x % 10;
      x /= 10;
    } while (x);
    for (int i = p; i >= 1; i--) putchar(buf[i] + '0');
    if (split != '\0') putchar(split);
  }
  void puts(char const *str, const char split = '\n') {
    while (*str) putchar(*(str++));
    putchar(split);
  }
  void lf() { putchar('\n'); }
  ~IO() { fwrite(obuf, sizeof(char), onow - obuf, stdout); }
} io;
long long ans;
int val[maxn], f[maxn], cnt[maxn], n;
void init() {
  for (int i = 0; i < maxn; i++) f[i] = i;
}
int find(const int x) { return x == f[x] ? x : f[x] = find(f[x]); }
void merge(const int a, const int b) {
  const int x = find(a), y = find(b);
  f[x] = y;
}
int main() {
  io.read(n);
  for (int i = 1; i <= n; i++) io.read(val[i]), cnt[val[i]]++;
  cnt[0]++;
  init();
  for (int w = (1 << 18) - 1; w >= 0; w--)
    for (int s = w; s; s = (s - 1) & w) {
      const int a = s, b = w ^ s;
      if (!cnt[a] || !cnt[b]) continue;
      if (find(a) == find(b)) continue;
      merge(a, b);
      ans += 1ll * w * (cnt[a] + cnt[b] - 1);
      cnt[a] = cnt[b] = 1;
    }
  for (int i = 1; i <= n; i++) ans -= val[i];
  io.write(ans, '\n');
  return 0;
}