#include<bits/stdc++.h>
#define int int64_t
using namespace std;

const int N = 1e5 + 10;

int t[4 * N],A[N];

void build(int v,int tl,int tr){
    if(tl == tr){
        t[v] = A[tl];
        return;
    }
    int mid = (tl + tr) >> 1;
    build(v * 2,tl,mid);
    build(v * 2 + 1,mid + 1,tr);
    t[v] = min(t[v * 2],t[v * 2 + 1]);
}


void solve(){
    int n;
    cin >> n;
    vector<int>a(n);
    unordered_map<int,int>mp,mpcnt;
    for(int i = 0; i < n; ++ i){
        cin >> a[i];
        mp[a[i]] ++ ;
    }
    if(n == 1){
        cout << a[0] << '\n';
        return;
    }
    int st = __lg(n) + 1;
    for(auto [x,y] : mp){
        mpcnt[y]++;
        if(y > st){
            cout << "-1\n";
            return;
        }
    }
    vector<int>ans;
    for(int i = 0; i < st; ++ i){
        if(i == 0){
            if(mpcnt[st] != 1){
                cout << "-1\n";
                return;
            }
        }
        else {
            if(mpcnt[st - i] != i){
                cout << "-1\n";
                return;
            }
        }
    }
    vector<array<int,2>>v;
    for(auto [x,y] : mp){
        v.push_back({x,y});
    }
    sort(v.begin(),v.end(),[&](auto x,auto y){
        return x[1] < y[1];
    });
    int mid = v.size() / 2,i = 0;
    while(mid < v.size()){
        ans.push_back(v[i][0]);
        ans.push_back(v[mid][0]);
        mid ++ ;
        i ++ ;
    }
    for(auto to : ans)cout << to << ' ';
}

int32_t main(){
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int Q = 1;
//    cin >> Q;
    while(Q -- )solve();
    return 0;
}
