#include <bits/stdc++.h>
using namespace std;
int fa[400086], siz[400086];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int n;
int cnt[400086];
int x, y;
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    ++cnt[x];
    ans -= x;
  }
  for (int i = 0; i <= 2e5; i++) fa[i] = i, siz[i] = 1;
  ++cnt[0];
  for (int i = 1 << 18; i; i--) {
    for (int j = i;; j = (j - 1) & i) {
      int k = i ^ j;
      if (cnt[j] && cnt[k]) {
        x = find(j), y = find(k);
        if (x != y) {
          if (siz[x] > siz[y]) swap(x, y);
          siz[y] += siz[x];
          fa[x] = y;
          ans += 1ll * (cnt[j] + cnt[k] - 1) * i;
          cnt[j] = cnt[k] = 1;
        }
      }
      if (!j) break;
    }
  }
  printf("%lld", ans);
}
