#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
class BuildingHeights { public:
int minimum(vector <int> heights)
{
const int N = heights.size();
sort(heights.begin(), heights.end());
vector<int> sum(N+1);
partial_sum(heights.begin(), heights.end(), sum.begin()+1);
vector<int> A(N, 0x7fffffff);
for(int s=0; s<N; ++s)
for(int e=s+1; e<=N; ++e)
{
int M = e-s;
int Max = heights[e-1];
int Sum = sum[e] - sum[s];
A[M-1] = min(A[M-1], Max*M-Sum);
}
int ans = 0;
for(int a: A) ans ^= a;
return ans;
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, BuildingHeights().minimum(heights));}
int main(){
CASE(0)
int heights_[] = {1, 5, 4, 3, 8};
vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_));
int _ = 22;
END
CASE(1)
int heights_[] = {1, 2, 3};
vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_));
int _ = 2;
END
CASE(2)
int heights_[] = {3, 4, 1, 6, 8, 1};
vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_));
int _ = 21;
END
CASE(3)
int heights_[] = {990, 20, 2359, 1667, 51, 2455, 1659, 1093, 2015, 205, 656, 752, 1760, 1594, 857,
2033, 1868, 1932, 2408, 1518, 91, 2220, 1696, 1552, 933, 143, 1888, 1261, 2298, 1975,
929, 2139, 1994, 2139, 158, 896, 2093, 1816, 841, 459, 2020, 1496, 63, 131, 589, 919,
1015, 1308, 350, 922, 326, 1792, 641, 2021, 843, 425, 1015, 231, 1685, 2165, 1057,
1465, 655, 550, 1103, 812, 297, 2048, 1479, 1137, 6, 2350, 1484, 1420, 1332, 925, 2338,
1198, 2232, 1539, 2119, 57, 830, 1611, 929, 525, 888};
vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_));
int _ = 56068;
END
/*
CASE(4)
int heights_[] = ;
vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_));
int _ = ;
END
CASE(5)
int heights_[] = ;
vector <int> heights(heights_, heights_+sizeof(heights_)/sizeof(*heights_));
int _ = ;
END
*/
}
// END CUT HERE