# include <bits/stdc++.h>

# define fr first
# define sc second
# define pb push_back
# define ll unsigned long long
# define mk make_pair
# define sz(s) (int)s.size()
# define all(s) s.begin(), s.end()

using namespace std;

const int N = 2e5+10;
const int inf = 1e9+7;

int n, cnt = 0;
int a[N][3];
pair <int, int> t[4*N][3];
pair <int, int> b[N];
vector <pair <int, int> > ans;

void build(int v, int tl, int tr, int o) {
    if(tl == tr) {
        t[v][o] = mk(a[tl][o], tl);
        return;
    }
    int tm = (tl + tr) / 2;
    build(v + v, tl, tm, o);
    build(v + v + 1, tm + 1, tr, o);
    t[v][o] = t[v + v][o];
    if(t[v][o].fr > t[v + v + 1][o].fr)
        t[v][o] = t[v + v + 1][o];
}

pair <int, int> get(int v, int tl, int tr, int l, int r, int o) {
    if(l > r) return mk(inf, inf);

    if(tl == l && r == tr) {
        return t[v][o];
    }
    int tm = (tl + tr) / 2;

    pair <int, int> nw = get(v + v, tl, tm, l, min(tm, r), o);
    pair <int, int> nw2 = get(v + v + 1, tm + 1, tr, max(tm + 1, l), r, o);

    if(nw.fr < nw2.fr) return nw;
    return nw2;
}

vector <int> g[N];

int co(int n) {
    return n * 2 - 1;
}

int ce(int n) {
    return n * 2;
}

void A(int l, int r, int p) {
    if(l >= r) return;
    int num = ++cnt;
    g[p].pb(num);
    if(l & 1) {
        int pos = get(1, 1, n / 2, (l + 1) / 2, r / 2, 1).sc;
        int ps = get(1, 1, n / 2, (l + 1) / 2, r / 2, 2).sc;
        b[num] = mk(co(pos), ce(ps));
        A(l, co(pos) - 1, num);
        A(co(pos) + 1, ce(ps) - 1, num);
        A(ce(ps) + 1, r, num);
    }
    else {
        int pos = get(1, 1, n / 2, l / 2, r / 2, 2).sc;
        int ps = get(1, 1, n / 2, l / 2 + 1, r / 2 + 1, 1).sc;
        b[num] = mk(ce(pos), co(ps));
        A(l, ce(pos) - 1, num);
        A(ce(pos) + 1, co(ps) - 1, num);
        A(co(ps) + 1, r, num);
    }
}

inline void solve() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i][0]);
        if(i & 1)
            a[(i + 1) / 2][1] = a[i][0];
        else
            a[i / 2][2] = a[i][0];

    }
    build(1, 1, n / 2, 1);
    build(1, 1, n / 2, 2);

    A(1, n, 0);

    set <pair <int, int> > st;
    st.insert(mk(0, 0));
    while(!st.empty()) {
        int ok = st.begin()->sc;
        st.erase(st.begin());
        if(ok != 0)
            ans.pb(b[ok]);
        for(int j = 0; j < g[ok].size(); j++)
            st.insert(mk(a[b[g[ok][j]].fr][0], g[ok][j]));
    }
    for(int i = 0; i < sz(ans); i++)
        cout << a[ans[i].fr][0] << " " << a[ans[i].sc][0] << " ";
}


int test = 1;

int main() {
    while(test--) {
        solve();
    }
}
