#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<long long, long long>>> g;
int32_t main() {
  ios_base::sync_with_stdio(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  vector<long long> cnt(20);
  for (long long i = 0; i < (long long)(n); ++i) {
    cin >> a[i];
    for (long long j = 0; j < (long long)(20); ++j) {
      if (a[i] & (1 << j)) {
        cnt[j]++;
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < (long long)(n); ++i) {
    long long cur = 0;
    for (long long j = 0; j < (long long)(20); ++j) {
      if (cnt[j] > i) {
        cur |= 1 << j;
      }
    }
    ans += cur * cur;
  }
  cout << ans << endl;
}
