#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  vector<long long> v[20];
  long long n;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    for (long long j = 0; j < 20; j++) {
      if ((arr[i] & (1 << j)) != 0) v[j].push_back(i);
    }
  }
  for (long long i = n - 1; i >= 0; i--) {
    for (long long j = 0; j < 20; j++) {
      if ((arr[i] & (1 << j)) != 0) {
        v[j].pop_back();
        continue;
      }
      if ((long long)v[j].size() == 0) continue;
      long long idx = v[j][(long long)v[j].size() - 1];
      v[j].pop_back();
      arr[idx] ^= (1 << j);
      arr[i] ^= (1 << j);
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) ans += (arr[i] * arr[i]);
  cout << ans << '\n';
}
