#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  vector<vector<bool>> b(n, vector<bool>(32, 0));
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < 32; j++) {
      b[i][j] = ((a[i] >> j) & 1);
    }
  }
  vector<ll> x(32, 0);
  for (ll i = 0; i < n; i++)
    for (ll j = 0; j < 32; j++)
      if (b[i][j]) x[j]++;
  vector<vector<bool>> ans(n, vector<bool>(32));
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < 32; j++) {
      if (x[j] > 0) ans[i][j] = true, x[j]--;
    }
  }
  vector<ll> num(n, 0);
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < 32; j++) {
      num[i] += pow(2, j) * ans[i][j];
    }
  }
  ll res = 0;
  for (auto it : num) res += it * it;
  cout << res << "\n";
  return 0;
}
