#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while (((c = getchar()) == ' ') || c == '\n')
    ;
  x = c;
}
int n, m, i, j, a[200005], fa[262145], c[262145];
long long ans;
int fnd(int x) {
  if (fa[x] == x) return x;
  return fa[x] = fnd(fa[x]);
}
int main() {
  read(n);
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) read(a[i]);
  c[0] = 1;
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
    ans -= a[i];
    c[a[i]]++;
  }
  for (((i)) = (0); ((i)) <= (((int)((1 << 18))) - 1); ((i))++) fa[i] = i;
  for (i = (1 << 18) - 1; i; i--) {
    for (j = i; j; j = ((j - 1) & i)) {
      if (c[j] && c[i ^ j] && fnd(j) != fnd(i ^ j)) {
        int x = fnd(j), y = fnd(i ^ j);
        ans += 1ll * i * (c[x] + c[y] - 1);
        c[x] = c[y] = 1;
        fa[x] = y;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
