#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n;
int a[N], f[N], cnt[N], fa[N];
long long ans;
inline int findf(int x) { return x == fa[x] ? x : fa[x] = findf(fa[x]); }
inline void merge(int u, int v, int w) {
  u = findf(u), v = findf(v);
  if (u == v) return;
  ans += 1ll * (cnt[u] + cnt[v] - 1) * w;
  fa[u] = v, cnt[u] = cnt[v] = 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), ans -= a[i], cnt[a[i]]++;
  for (int i = 0; i < (1 << 18); i++) fa[i] = i;
  cnt[0]++;
  for (int i = (1 << 18) - 1; i >= 0; i--) {
    for (int s = i; s; s = (s - 1) & i)
      if (cnt[s] && cnt[i ^ s]) merge(s, i ^ s, i);
  }
  printf("%lld", ans);
  return 0;
}
