#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 18;
const long long mod = 998244353;
int cnt[N], fa[N];
int dsu(int x) {
  if (fa[x] == x) return x;
  return fa[x] = dsu(fa[x]);
}
long long ans;
void solve(int u, int v) {
  if (!cnt[u] || !cnt[v]) return;
  if (dsu(u) == dsu(v)) return;
  fa[dsu(u)] = dsu(v);
  ans += 1ll * (u | v) * (cnt[u] + cnt[v] - 1);
  cnt[u] = 1;
  cnt[v] = 1;
}
int main() {
  int n, x;
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) {
    scanf("%d", &x);
    ans -= x;
    cnt[x]++;
  }
  cnt[0]++;
  for (int i = (0); i < (N); ++i) fa[i] = i;
  for (int i = (N)-1; i >= (0); --i) {
    for (int j = i; j > (i ^ j); j = (j - 1) & i) {
      solve(j, j ^ i);
    }
  }
  printf("%lld", ans);
}
