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

#define ll long long
#define f first
#define s second
#define sz size
#define pb push_back
#define all(x) x.begin(),x.end()

int main(){
    int n;
    cin >> n;
    int a[n+1];
    map<int,int> d;
    for(int i=1; i<=n; i++) {
        cin >> a[i];
        d[a[i]]++;
    }
    vector<int> cnt3[25];
    int k=log2(n+1)-1;
    vector<pair<int,int> > cnt1;
    vector<int> cnt2;
    for(auto x:d) {
        cnt1.pb({x.s,x.f});
        cnt3[x.s].pb(x.f);
    }
    sort(all(cnt1));
    reverse(all(cnt1));

    cnt2.pb(k+1), cnt2.pb(k);
    int l=2, c=k-1;
    while(c>=1) {
        for(int i=1; i<=l; i++) {
            cnt2.pb(c);
        }
        c--,l*=2;
    }

    for(int i=0; i<cnt1.sz(); i++) {
        if(cnt1[i].f!=cnt2[i]) {
            cout << -1;
            return 0;
        }
    }

    vector<int> ans;
    c=0;
    ans.pb(1);
    while(c<k) {
        l=ans.sz();
        for(int i=0; i<l; i++) {
            ans.pb(ans[i]);
        }
        ans[0]++, c++;
    }

    for(int i=0; i<ans.sz(); i++) {
        cout << cnt3[ans[i]][0] << " ";
        cnt3[ans[i]].erase(cnt3[ans[i]].begin());
    }

    return 0;
}
