#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 19;
multiset<int, greater<int> > st;
vector<int> num[21];
void insert(int x) {
  for (int i = 0; i < 20; ++i)
    if (x & (1 << i)) num[i].push_back(x);
  st.insert(x);
}
int get(int pos) {
  while (num[pos].size() != 0) {
    int v = num[pos].back();
    if (!st.count(v)) {
      num[pos].pop_back();
      continue;
    } else
      break;
  }
  if (num[pos].size() == 0) return -1;
  int v = num[pos].back();
  num[pos].pop_back();
  st.erase(st.lower_bound(v));
  return v;
}
void solve() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    insert(x);
  }
  long long ans = 0;
  while (st.size()) {
    int v = *st.begin();
    st.erase(st.lower_bound(v));
    for (int i = 0; i < 20; ++i) {
      int p = get(i);
      if (p == -1) continue;
      int t = (p & v);
      v |= p;
      p = t;
      insert(p);
    }
    ans += 1ll * v * v;
  }
  printf("%lld\n", ans);
}
int main() {
  int T = 1;
  for (int i = 1; i <= T; ++i) solve();
  return 0;
}
