#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;
typedef vector<pi> vp;
typedef vector<bool> vb;

vector<vi> s;

vi f(int x){

    vi sol;
    for(int i = 0; i < 50; ++i){
        sol.push_back(x % 2);
        x/=2;
    }

    //reverse(sol.begin(), sol.end());
    return sol;
}

vi p = {1};

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);

    int n;
    cin >> n;

    for (int i = 1; i < 50; ++i)
        p.push_back(2 * p[i - 1]);

    vi a(n);
    for (auto& i : a){
            cin >> i;
        s.push_back(f(i));
    }

    int cena = INT64_MAX;
    vi r;
    int k = -1;
    for (int i = 0; i < 40; ++i){
            vi b;
            int jed = 0, nul = 0;
        for (int j = 0; j < n; ++j){
            if (s[j][i]){
                ++jed;
            } else {++nul; b.push_back(j);}
        }

        if (cena > p[i] * nul){
            r = b;
            k = i;
            cena = p[i] * nul;
        }
    }
    
    if (n % 2){
    for (auto& i : r){
        for (int j = k - 1; j >= 0; --j){
            cena -= p[j];
        }
        cout << cena << '\n';
    }} else {
        throw SIGSEGV;
    }
}