#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;
const ld EPS = (ld) 1e-12;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; i++)
#define per(i, f, t) for (auto i = f; i >= t; i--)

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

void add(ll &x, ll y, ll mod = MOD) {
    x += y;
    if (x >= mod) x -= mod;
    if (x < 0) x += mod;
}

ll sum(ll x, ll y, ll mod = MOD) {
    add(x, y, mod);
    return x;
}

ll mult(ll x, ll y, ll mod = MOD) {
    return (x * y) % mod;
}

ll div(ll x, ll y, ll mod) {
    return x * power(y, mod - 2, mod);
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

template<typename T> void read(T first, T last) {
    while (first != last) {
        cin >> *(first++);
    }
}

template<typename T> void print(T first, T last) {
    while (first != last) {
        cout << *(first++) << " ";
    }
    cout << "\n";
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

const int N = (int) 4e5 + 123;

struct Node {
    bool rev;
    pair<int, int> min_black, min_white;
};

int n;
int p[N];
set<int> used, rest;

Node tree[4 * N];

void push(int i, int tl, int tr) {
    if (tl >= tr) return;
    if (!tree[i].rev) return;
    swap(tree[i].min_black, tree[i].min_white);
    if (tl != tr - 1) {
        tree[2 * i + 1].rev ^= 1;
        tree[2 * i + 2].rev ^= 1;
    }
    tree[i].rev = 0;
}

void recalc(int i, int tl, int tr) {
    if (tl >= tr) return;
    if (tl == tr - 1) {
        return;
    }
    tree[i].min_black = min(tree[2 * i + 1].min_black, tree[2 * i + 2].min_black);
    tree[i].min_white = min(tree[2 * i + 1].min_white, tree[2 * i + 2].min_white);
}

void build(int i, int tl, int tr) {
    if (tl == tr - 1) {
        tree[i].min_black = tree[i].min_white = {INF, tl};
        if (tl & 1) {
            tree[i].min_white = {p[tl], tl};
        } else {
            tree[i].min_black = {p[tl], tl};
        }
        return;
    }
    int tm = (tl + tr) / 2;
    build(2 * i + 1, tl, tm);
    build(2 * i + 2, tm, tr);
    recalc(i, tl, tr);
}

void build() {
    build(0, 0, n);
}

void disable(int i, int tl, int tr, int pos) {
    push(i, tl, tr);
    if (tl == tr - 1) {
        tree[i].min_black = tree[i].min_white = {INF, tl};
        return;
    }
    int tm = (tl + tr) / 2;
    if (pos < tm) disable(2 * i + 1, tl, tm, pos);
    else disable(2 * i + 2, tm, tr, pos);
    push(2 * i + 1, tl, tm);
    push(2 * i + 2, tm, tr);
    recalc(i, tl, tr);
}

void recolor(int i, int tl, int tr, int l, int r) {
    push(i, tl, tr);
    if (tl >= r || tr <= l) {
        return;
    }
    
    if (l <= tl && tr <= r) {
        tree[i].rev = 1;
        push(i, tl, tr);
        return;
    }
    
    int tm = (tl + tr) / 2;
    recolor(2 * i + 1, tl, tm, l, r);
    recolor(2 * i + 2, tm, tr, l, r);
    recalc(i, tl, tr);
}

void recolor(int l, int r) {
    recolor(0, 0, n, l, r);
}

void disable(int pos) {
    used.insert(pos);
    rest.erase(pos);
    disable(0, 0, n, pos);
}

pair<int, int> get_min_black(int i, int tl, int tr, int l, int r) {
    push(i, tl, tr);
    if (tl >= r || tr <= l) {
        return {INF, INF};
    }
    
    if (l <= tl && tr <= r) {
        return tree[i].min_black;
    }
    
    int tm = (tl + tr) / 2;
    auto res = min(get_min_black(2 * i + 1, tl, tm, l, r), get_min_black(2 * i + 2, tm, tr, l, r));
    recalc(i, tl, tr);
    return res;
}

pair<int, int> get_min_white(int i, int tl, int tr, int l, int r) {
    push(i, tl, tr);
    if (tl >= r || tr <= l) {
        return {INF, INF};
    }
    
    if (l <= tl && tr <= r) {
        return tree[i].min_white;
    }
    
    int tm = (tl + tr) / 2;
    auto res = min(get_min_white(2 * i + 1, tl, tm, l, r), get_min_white(2 * i + 2, tm, tr, l, r));
    recalc(i, tl, tr);
    return res;
}

pair<int, int> get_min_black(int l, int r) {
    return get_min_black(0, 0, n, l, r);
}

pair<int, int> get_min_white(int l, int r) {
    return get_min_white(0, 0, n, l, r);
}

void run() {
    cin >> n;
    read(p, p + n);
    build();
    vector<int> q;
    used.insert(n);
    rep(i, 0, n) rest.insert(i);
    
    rep(iter, 0, n / 2) {
        {
            int f = *rest.begin();
            auto it = get_min_black(f, f + 1);
            if (it.first == INF) {
                recolor(0, n);
            }
        }

        pair<int, int> best_black = get_min_black(0, n);
        int val = best_black.first;
        assert(1 <= best_black.first && best_black.first <= n);
        int pos = best_black.second;
        int border = *used.lower_bound(pos);
        pair<int, int> best_white = get_min_white(pos + 1, border);
        int val_white = best_white.first;
        int pos_white = best_white.second;
        assert(1 <= val_white && val_white <= n);
        q.pb(val);
        q.pb(val_white);
        recolor(pos + 1, pos_white);
        disable(pos);
        disable(pos_white);
    }
    
    print(all(q));
}


Measured memory_bytes: 44660