#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
const int lg = 18;
const int N = 1 << lg | 5;
int sub[N], par[N], cnt[N], n;
int find(int u) { return par[u] == u ? u : par[u] = find(par[u]); }
inline int single(int u) { return par[u] == u and sub[u] == 1; }
int unite(int u, int v) {
  int ret = 0;
  if (single(u) and single(v)) {
    ret = cnt[u] + cnt[v] - 1;
  } else if (single(u)) {
    ret = cnt[u];
  } else if (single(v)) {
    ret = cnt[v];
  } else {
    ret = find(u) != find(v);
  }
  u = find(u), v = find(v);
  if (sub[u] > sub[v]) swap(u, v);
  if (u != v) {
    par[u] = v, sub[v] += sub[u];
  }
  return ret;
}
int main(int argc, char const *argv[]) {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  ll total = 0;
  scanf("%d", &n);
  for (int i = 0, x; i < n; i++) {
    scanf("%d", &x);
    cnt[x]++, total -= x;
  }
  cnt[0]++;
  iota(par, par + N, 0);
  fill(sub, sub + N, 1);
  for (int both = (1 << lg) - 1; both >= 0; both--) {
    for (int u = both; u > 0; u = (u - 1) & both) {
      int v = both ^ u;
      if (cnt[u] and cnt[v]) {
        total += (ll)both * unite(u, v);
      }
    }
  }
  printf("%lld\n", total);
  return 0;
}
