#include <bits/stdc++.h>
using namespace std;
const int N = (int)3e5 + 123, mod = (int)1e9 + 7, inf = (int)1e9;
const long long INF = (long long)1e18;
int n, a[100];
long long ans;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(NULL);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    for (int j = 0; j < 20; ++j)
      if ((x >> j) & 1) a[j]++;
  }
  for (int i = 0; i < 20; ++i) {
    long long x = 0;
    long long mn = n;
    for (int j = 0; j < 20; ++j) {
      if (a[j] == 0) continue;
      x ^= (1LL << j);
      mn = min(mn, (long long)a[j]);
    }
    if (x == 0) break;
    for (int j = 0; j < 20; ++j)
      if (a[j] > 0) a[j] -= mn;
    ans += x * x * mn;
  }
  cout << ans;
  return 0;
}
