#include <bits/stdc++.h>
using namespace std;
int freq[21];
int fmin() {
  int mn = 1e6;
  for (int i = 0; i <= 20; i++)
    if (freq[i] != 0) mn = min(mn, freq[i]);
  if (mn == 1e6) return -1;
  return mn;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int ar[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
    for (int j = 0; j <= 20; j++) freq[j] += ((bool)(ar[i] & (1 << j)));
  }
  long long sum = 0;
  int m;
  while ((m = fmin()) != -1) {
    long long cur = 0;
    for (int j = 0; j <= 20; j++) {
      if (freq[j]) cur += (1 << j), freq[j] -= m;
    }
    sum += m * cur * cur;
  }
  cout << sum << endl;
  return 0;
}
