#include<map>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 600006
#define LL long long 
#define int long long 
using namespace std;

int n,m;
int a[N];
map<int,int>mp;
LL ans;
inline int qr()
{
	char a=0;int w=1,x=0;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'&&a>='0'){x=(x<<3)+(x<<1)+(a^48);a=getchar();}
	return x*w;
}

signed main()
{
	n=qr();
	for(register int i=1;i<=n;i++) mp[a[i]=qr()]++;
	sort(a+1,a+n+1);
	for(register int i=1;i<=n;i++)
	{
		for(register int j=-205;j<=a[i];j++)
			ans+=(a[i]-j)*(a[i]-j)*mp[j];
	}
	// for(register int i=-200;i<=200;i++)
	// 	for(register int j=i;j<=200;j++)
	// 		if(mp[i]&&mp[j])
	// 			ans+=(LL)(j-i)*(j-i)*mp[i]*mp[j];
	cout<<ans<<endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int N; cin>>N;
    vec_int A(N); rep(i,N)cin>>A.at(i);
    int ans = (int)pow(10,18);

    for(int i=0;i<(1<<(N-1));i++){
        int temp = A.at(0);
        int temp_ans = 0;

        int a = 1;
        for(int j=1;j<N;j++){
            if((i/a)%2==1){
                temp_ans = temp_ans^temp;
                temp = A.at(j);
            }else{
                temp = (temp | A.at(j));
            }
            a *= 2;
        }
        temp_ans = temp_ans^temp;
        ans = min(temp_ans, ans);

    }
    cout<<ans<<endl;




    return 0;
}