#include <stdio.h>
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <random>
#include <chrono>
#include <queue>
#include <functional>
#include <iostream>
#include <queue>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
 
const ll maxn = 1e6 + 1, maxm = 1e7 + 1;
const ll mod = 1500000059, mod2 = 998244353, inf = 1e9, block = 550, hb = 1000012337, base = 1000050017;
const ld eps = 1e-3;
 
int n;
int a[maxn], ans[maxn * 4], b[maxn];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    map<int, int> was, was2;
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
        was[a[i]] += 1;
    }
    
    set<pair<int, int>> setik;
    for (int i = 1; i <= n; ++i){
        if (was[a[i]] > 0){
            setik.insert(mp(was[a[i]], a[i]));
            was[a[i]] = 0;
        }
    }
    queue<int> q;

    q.push(1);
    vector<int> answ;
    while (q.size() > 0){
        int v = q.front();
        q.pop();
        if (ans[v]){
            if (v + v <= n){
                ans[v + v] = ans[v];
            }
        }
        else{
            if ((int)setik.size() == 0){
                cout << -1;
                exit(0);
            }
            pair<int, int> mn = *setik.rbegin();
            ans[v] = mn.s;
            setik.erase(mn);
            if (v + v <= n){
                ans[v + v] = ans[v];
            }
        }
      
        //  cout << v << " " << ans[v] << '\n';
        if (!(v + v <= n || v + v + 1 <= n)){
            answ.pb(ans[v]);
        }
        if (ans[v + v] == 0 && v + v <= n){
            q.push(v + v);
        }
        if (ans[v + v + 1] == 0 && v + v + 1 <= n){
            q.push(v + v + 1);
        }
        if (ans[v + v] && v + v <= n){
            q.push(v + v);
        }
        if (ans[v + v + 1] && v + v + 1 <= n){
            q.push(v + v + 1);
        }
    }

    for (int i = 1; i <= n; ++i){
        was[a[i]] += 1;
        was2[ans[i]] += 1;
    }
    for (int i = 1; i <= n; ++i){
        if (was[a[i]] != was2[a[i]]){
            cout << -1;
            exit(0);
        }
        if (i + i <= n && i + i + 1 <= n){
            if (ans[i + i] == ans[i + i + 1]){
                cout << -1;
                exit(0);
            }
        }
        if (i + i <= n && ans[i] > ans[i + i]){
            cout << -1;
            exit(0);
        }
        if (i + i + 1 <= n && ans[i] > ans[i + i + 1]){
            cout << -1;
            exit(0);
        }
      //  cout << ans[i] << " ";
    }
    for (auto it : answ){
        cout << it << " ";
    }
}
