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>
const int N = 262154, ALL = 262143;
int n;
int a[N];
int p[N], size[N];
std::pair<int, int> max[N], cc[N], empty;
int ancestor(int x) { return p[x] == x ? x : (p[x] = ancestor(p[x])); }
inline bool test(int x, int y, bool un = false) {
  if ((x = ancestor(x)) == (y = ancestor(y))) return true;
  return un && (size[x] < size[y] ? (p[x] = y, size[y] += size[x])
                                  : (p[y] = x, size[x] += size[y]),
                false);
}
inline void up(std::pair<int, int> &x, const int y) {
  if (a[x.first] < a[y])
    test(x.first, y) || (x.second = x.first), x.first = y;
  else if (a[x.second] < a[y] && !test(x.first, y))
    x.second = y;
}
inline void up(std::pair<int, int> &x, const std::pair<int, int> &y) {
  up(x, y.first), up(x, y.second);
}
inline void up(std::pair<int, int> &x, const int y, const int z) {
  if (!test(y, z) && a[x.first] + a[x.second] < a[y] + a[z])
    x = std::pair<int, int>(y, z);
}
inline void up(std::pair<int, int> &x, const int y,
               const std::pair<int, int> &z) {
  up(x, y, z.first), up(x, y, z.second);
}
int main() {
  int i, j, k, len, nCC;
  long long ans = 0;
  scanf("%d", &n), p[n + 1] = nCC = n + 1, a[nCC] = -1,
                         empty = std::pair<int, int>(nCC, nCC);
  for (i = 1; i <= n; ++i)
    scanf("%d", a + i), ans -= a[i], p[i] = i, size[i] = 1;
  for (; nCC > 1;) {
    for (i = 0; i <= ALL; ++i) max[i] = empty;
    for (i = 0; i <= n; ++i)
      if (p[i] == i) cc[i] = empty;
    for (i = 0; i <= n; ++i) up(max[a[i]], i);
    for (len = 1, i = 0; i < 18; ++i, len <<= 1)
      for (j = 0; j <= ALL; j += len << 1)
        for (k = j; k < j + len; ++k) up(max[k + len], max[k]);
    for (i = 0; i <= n; ++i) up(cc[ancestor(i)], i, max[~a[i] & ALL]);
    for (i = 0; i <= n; ++i)
      if (p[i] == i)
        if (cc[i].second != n + 1 && !test(i, cc[i].second, true))
          --nCC, ans += a[cc[i].first] + a[cc[i].second];
  }
  printf("%lld\n", ans);
  return 0;
}