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;
using ll = long long;
template <class t, class u>
void chmax(t& first, u second) {
  if (first < second) first = second;
}
template <class t, class u>
void chmin(t& first, u second) {
  if (second < first) first = second;
}
template <class t>
using vc = vector<t>;
template <class t>
using vvc = vc<vc<t>>;
using pi = pair<ll, ll>;
using vi = vc<ll>;
template <class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
  return os << "{" << p.first << "," << p.second << "}";
}
template <class t>
ostream& operator<<(ostream& os, const vc<t>& v) {
  os << "{";
  for (auto e : v) os << e << ",";
  return os << "}";
}
using uint = unsigned;
using ull = unsigned long long;
template <class t, size_t n>
ostream& operator<<(ostream& os, const array<t, n>& first) {
  return os << vc<t>(first.begin(), first.end());
}
template <ll i, class T>
void print_tuple(ostream&, const T&) {}
template <ll i, class T, class H, class... Args>
void print_tuple(ostream& os, const T& t) {
  if (i) os << ",";
  os << get<i>(t);
  print_tuple<i + 1, T, Args...>(os, t);
}
template <class... Args>
ostream& operator<<(ostream& os, const tuple<Args...>& t) {
  os << "{";
  print_tuple<0, tuple<Args...>, Args...>(os, t);
  return os << "}";
}
template <class t>
void print(t x, ll suc = 1) {
  cout << x;
  if (suc == 1) cout << "\n";
  if (suc == 2) cout << " ";
}
ll read() {
  ll i;
  cin >> i;
  return i;
}
vi readvi(ll n, ll off = 0) {
  vi v(n);
  for (ll i = ll(0); i < ll(n); i++) v[i] = read() + off;
  return v;
}
template <class T>
void print(const vector<T>& v, ll suc = 1) {
  for (ll i = ll(0); i < ll(v.size()); i++)
    print(v[i], i == ll(v.size()) - 1 ? suc : 2);
}
string readString() {
  string s;
  cin >> s;
  return s;
}
template <class T>
T sq(const T& t) {
  return t * t;
}
void yes(bool ex = true) {
  cout << "Yes"
       << "\n";
  if (ex) exit(0);
}
void no(bool ex = true) {
  cout << "No"
       << "\n";
  if (ex) exit(0);
}
void possible(bool ex = true) {
  cout << "Possible"
       << "\n";
  if (ex) exit(0);
}
void impossible(bool ex = true) {
  cout << "Impossible"
       << "\n";
  if (ex) exit(0);
}
constexpr ll ten(ll n) { return n == 0 ? 1 : ten(n - 1) * 10; }
const ll infLL = LLONG_MAX / 3;
const ll inf = infLL;
ll topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
ll topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
ll botbit(signed first) { return first == 0 ? 32 : __builtin_ctz(first); }
ll botbit(ll first) { return first == 0 ? 64 : __builtin_ctzll(first); }
ll popcount(signed t) { return __builtin_popcount(t); }
ll popcount(ll t) { return __builtin_popcountll(t); }
bool ispow2(ll i) { return i && (i & -i) == i; }
ll mask(ll i) { return (ll(1) << i) - 1; }
template <class t>
bool inc(t first, t second, t c) {
  return first <= second && second <= c;
}
template <class t>
void mkuni(vc<t>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
ll rand_int(ll l, ll r) {
  static mt19937_64 gen;
  return uniform_int_distribution<ll>(l, r)(gen);
}
template <class t>
ll lwb(const vc<t>& v, const t& first) {
  return lower_bound(v.begin(), v.end(), first) - v.begin();
}
struct unionfind {
  vi p, s;
  ll c;
  unionfind(ll n) : p(n, -1), s(n, 1), c(n) {}
  ll find(ll first) {
    return p[first] == -1 ? first : (p[first] = find(p[first]));
  }
  bool unite(ll first, ll second) {
    first = find(first);
    second = find(second);
    if (first == second) return false;
    p[second] = first;
    s[first] += s[second];
    c--;
    return true;
  }
  bool same(ll first, ll second) { return find(first) == find(second); }
  ll sz(ll first) { return s[find(first)]; }
};
template <class D>
struct dirmst {
  struct E {
    ll to, id;
    D cost;
    bool operator<(const E& e) const { return cost > e.cost; }
  };
  struct Q {
    using pq = priority_queue<E>;
    pq* q;
    D off;
    Q() : q(new pq()), off(0) {}
    ~Q() { delete q; }
    void push(E e) { q->push(e); }
    void merge(Q& x) {
      if (q->size() < x.q->size()) {
        swap(q, x.q);
        swap(off, x.off);
      }
      while (x.q->size()) {
        E e = x.q->top();
        x.q->pop();
        e.cost += x.off - off;
        q->push(e);
      }
    }
    E pop() {
      E e = q->top();
      q->pop();
      e.cost += off;
      return e;
    }
  };
  ll n, m;
  vc<Q> g;
  vi st, ci, fi, src;
  vc<D> cc;
  dirmst(ll nn) : n(nn), m(0), g(n), st(n), ci(n, -1), fi(n, -1), cc(n) {}
  void ae(ll s, ll t, D d) {
    src.push_back(s);
    g[s].push({t, m++, d});
  }
  pair<D, vi> calc(ll rt) {
    st[rt] = 2;
    vi p(m), idx;
    unionfind uf(n);
    D ans = 0;
    for (ll i = ll(0); i < ll(n); i++)
      if (!st[i]) {
        vi vs{i};
        st[i] = 1;
        vi ch;
        while (1) {
          ll first = vs.back();
          E e = g[first].pop();
          cc[first] = e.cost;
          ans += e.cost;
          ci[first] = e.id;
          if (fi[first] == -1) fi[first] = e.id;
          for (auto c : ch) p[c] = e.id;
          ch.clear();
          idx.push_back(e.id);
          ll to = uf.find(e.to);
          if (st[to] == 0) {
            vs.push_back(to);
            st[to] = 1;
          } else if (st[to] == 1) {
            ll r = vs.size(), l = r - 1;
            while (vs[l] != to) l--;
            for (ll j = ll(l); j < ll(r); j++) {
              g[vs[j]].off -= cc[vs[j]];
              if (l < j) {
                g[vs[l]].merge(g[vs[j]]);
                uf.unite(vs[l], vs[j]);
              }
            }
            for (ll j = ll(l); j < ll(r); j++) ch.push_back(ci[vs[j]]);
            vs.resize(l + 1);
          } else {
            break;
          }
        }
        for (auto v : vs) st[v] = 2;
      }
    vi tmp, waf(m);
    reverse(idx.begin(), idx.end());
    for (auto i : idx)
      if (!waf[i]) {
        tmp.push_back(i);
        ll x = fi[src[i]];
        while (x != i) {
          waf[x] = 1;
          x = p[x];
        }
      }
    return make_pair(ans, tmp);
  }
};
struct E {
  ll first, second, c;
};
pair<ll, vi> mst(ll n, vc<E> es) {
  unionfind uf(n);
  vi idx(es.size());
  iota(idx.begin(), idx.end(), 0);
  sort(idx.begin(), idx.end(), [&](ll i, ll j) { return es[i].c > es[j].c; });
  ll ans = 0;
  vi used;
  for (auto i : idx)
    if (uf.unite(es[i].first, es[i].second)) {
      ans += es[i].c;
      used.push_back(i);
    }
  return {ans, used};
}
using T = tuple<ll, ll, ll>;
struct ysp {
  T x[2];
  ysp() {
    for (ll k = ll(0); k < ll(2); k++) x[k] = T(-1, -1, -1);
  }
  void upd(T v) {
    for (ll k = ll(0); k < ll(2); k++)
      if (get<1>(x[k]) == get<1>(v)) {
        chmax(x[k], v);
        if (x[0] < x[1]) swap(x[0], x[1]);
        return;
      }
    for (ll k = ll(0); k < ll(2); k++)
      if (x[k] < v) swap(x[k], v);
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  const ll L = 18;
  const ll S = 1 << L;
  const ll M = S - 1;
  ll n;
  cin >> n;
  bool dbg = n < 0;
  vi first;
  if (dbg) {
    n = -n;
    first.resize(n);
    for (ll i = ll(0); i < ll(n); i++) first[i] = rand_int(0, M);
  } else
    first = readvi(n);
  vc<E> es;
  for (ll i = ll(0); i < ll(n); i++) es.push_back(E{i, n, first[i]});
  unionfind uf(n);
  while (1) {
    vc<ysp> mori(S);
    vi tmp(n);
    for (ll i = ll(0); i < ll(n); i++) tmp[i] = uf.find(i);
    for (ll i = ll(0); i < ll(n); i++) {
      mori[first[i]].upd(T(first[i], tmp[i], i));
    }
    for (ll i = ll(0); i < ll(L); i++)
      for (ll j = ll(0); j < ll(S); j++)
        if (!(j & 1 << i))
          for (ll k = ll(0); k < ll(2); k++) mori[j | 1 << i].upd(mori[j].x[k]);
    bool add = false;
    vc<T> mx(n, T(-1, -1, -1));
    for (ll i = ll(0); i < ll(n); i++) {
      T w = mori[M - first[i]].x[0];
      if (get<1>(w) == tmp[i]) w = mori[M - first[i]].x[1];
      if (get<1>(w) == -1) continue;
      add = true;
      chmax(mx[tmp[i]], T(first[i] + get<0>(w), i, get<2>(w)));
    }
    if (!add) break;
    for (ll i = ll(0); i < ll(n); i++)
      if (tmp[i] == i) {
        ll first, second, c;
        tie(c, first, second) = mx[i];
        if (c != -1) {
          uf.unite(first, second);
          es.push_back(E{first, second, c});
        }
      }
  }
  ll ans = mst(n + 1, es).first;
  if (0) {
    vc<E> z;
    for (ll i = ll(0); i < ll(n); i++) z.push_back(E{i, n, first[i]});
    for (ll i = ll(0); i < ll(n); i++)
      for (ll j = ll(0); j < ll(i); j++)
        if ((first[i] & first[j]) == 0) {
          z.push_back(E{i, j, first[i] + first[j]});
        }
    ll tmp = mst(n + 1, z).first;
    assert(ans == tmp);
  }
  ans -= accumulate(first.begin(), first.end(), ll(0));
  cout << ans << endl;
}