#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;
typedef pair<int, Pii> PiP;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

class RMQ_segment_tree
{
    using data_type = Pii;

public:

    vector<data_type> dat;
    int N;
    data_type infinity;

    RMQ_segment_tree(int n, data_type inf){
        N = 1;
        while(n > N) N = N << 1;
        dat = vector<data_type>(2 * N - 1, inf);
        infinity = inf;
    }

    //k番目の値をaに更新
    void update(int k, data_type a){
        k += N - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1) / 2;
            dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    //[a, b)の最小値
    data_type minval(int a, int b){
        return query(a, b, 0, 0, N);
    }

    data_type query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return infinity;
        if(a <= l && r <= b) return dat[k];
        else{
            data_type vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            data_type vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};

signed main(){

    int N; cin >> N;
    vec p(N); readvec(p);

    RMQ_segment_tree even(N / 2, Pii(INF, -1)), odd(N / 2, Pii(INF, -1));
    REP(i, N / 2){
        even.update(i, Pii(p[2 * i], i));
        odd.update(i, Pii(p[2 * i + 1], i));
    }

    priority_queue<PiP> que;
    int maxv = even.minval(0, N / 2).first * (-1);
    que.push(PiP(maxv, Pii(0, N)));

    vec ans(0);

    while(!que.empty()){

        PiP q = que.top(); que.pop();
        int a = q.second.first, b = q.second.second, c, d;
        Pii tmp;
        if((a & 1) == 0){
            tmp = even.minval(a / 2, a / 2 + (b - a) / 2);
            ans.push_back(tmp.first);
            c = 2 * tmp.second;
            tmp = odd.minval(c / 2, c / 2 + (b - c) / 2);
            ans.push_back(tmp.first);
            d = 2 * tmp.second + 1;

            if(a < c){
                tmp = even.minval(a / 2, a / 2 + (c - a) / 2);
                que.push(PiP(-1 * tmp.first, Pii(a, c)));
            }
            if(c + 1 < d){
                tmp = odd.minval((c + 1) / 2, (c + 1) / 2 + (d - c - 1) / 2);
                que.push(PiP(-1 * tmp.first, Pii(c + 1, d)));
            }
            if(d + 1 < b){
                tmp = even.minval((d + 1) / 2, (d + 1) / 2 + (b - d - 1) / 2);
                que.push(PiP(-1 * tmp.first, Pii(d + 1, b)));
            }

        }else{
            tmp = odd.minval(a / 2, a / 2 + (b - a) / 2);
            ans.push_back(tmp.first);
            c = 2 * tmp.second + 1;
            tmp = even.minval((c + 1) / 2, (c + 1) / 2 + (b - c) / 2);
            ans.push_back(tmp.first);
            d = 2 * tmp.second;

            if(a < c){
                tmp = odd.minval(a / 2, a / 2 + (c - a) / 2);
                que.push(PiP(-1 * tmp.first, Pii(a, c)));
            }
            if(c + 1 < d){
                tmp = even.minval((c + 1) / 2, (c + 1) / 2 + (d - c - 1) / 2);
                que.push(PiP(-1 * tmp.first, Pii(c + 1, d)));
            }
            if(d + 1 < b){
                tmp = odd.minval((d + 1) / 2, (d + 1) / 2 + (b - d - 1) / 2);
                que.push(PiP(-1 * tmp.first, Pii(d + 1, b)));
            }

        }
    }

    REP(i, N) cout << ans[i] << " ";

    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 13984