#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

using P = pair<int, int>;
const static int INF = TEN(9);
/*
RBSTで書かれたStarry Sky Tree
*/

struct STree {
    using D = int;
    struct Node;
    using NP = Node*;
    static Node last_d;
    static NP last;
    struct Node {
        NP l, r;
        int sz;
        D v; P mi;
        Node(D v) :l(last), r(last), sz(1), v(v), mi(P(v, 0)) {}
        Node() :l(nullptr), r(nullptr), sz(0) {} //last用
        void push() {
            assert(this != last);
        }
        P sec(P p, int off) {
            return P(p.first, p.second + off);
        }
        NP update() {
            assert(this != last);
            sz = 1+l->sz+r->sz;
            mi = sec(P(v, 0), l->sz);
            if (l->sz) {
                mi = min(mi, l->mi);
            }
            if (r->sz) {
                mi = min(mi, sec(r->mi, l->sz + 1));
            }
            return this;
        }
        P get(int a, int b) {
            if (!sz || b <= 0 || sz <= a) return P(INF, -1);
            if (a <= 0 && sz <= b) return mi;
            push();
            P res = P(INF, -1);
            if (a <= l->sz && l->sz < b) res = min(res, sec(P(v, 0), l->sz));
            res = min(res, l->get(a, b));
            res = min(res, sec(r->get(a- l->sz - 1, b- l->sz - 1), l->sz + 1));
            return res;
        }
    } *n;


    static NP built(int sz, D d[]) {
        if (!sz) return last;
        int md = sz/2;
        NP x = new Node(d[md]);
        x->l = built(md, d);
        x->r = built(sz-(md+1), d+(md+1));
        return x->update();
    }

    static uint xor128(){
        static uint x=123456789,y=362436069,z=521288629,w=88675123;
        uint t;
        t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
    }
    static NP merge(NP l, NP r) {
        if (!l->sz) return r;
        if (!r->sz) return l; 
        l->push(); r->push();
        if ((int)(xor128() % (l->sz + r->sz)) < l->sz) {
            l->r = merge(l->r, r);
            return l->update();
        } else {
            r->l = merge(l, r->l);
            return r->update();
        }
    }
    static pair<NP, NP> split(NP x, int k) {
        if (!x->sz) return {last, last};
        x->push();
        if (k <= x->l->sz) {
            auto y = split(x->l, k);
            x->l = y.second;
            y.second = x->update();
            return y;
        } else {
            auto y = split(x->r, k- x->l->sz -1);
            x->r = y.first;
            y.first = x->update();
            return y;
        }
    }
    STree() : n(last) {}
    STree(NP n) : n(n) {}
    STree(D d) : n(new Node(d)) {}
    STree(int sz, D d[]) {
        n = built(sz, d);
    }
    int sz() {
        return n->sz;
    }
    void merge(STree r) {
        n = merge(n, r.n);
    }
    STree split(int k) {
        auto u = split(n, k);
        n = u.first;
        return STree(u.second);
    }
    void insert(int k, D x) {
        auto u = split(n, k);
        n = merge(merge(u.first, new Node(x)), u.second);
    }
    void erase(int k) {
        auto u = split(n, k);
        n = merge(u.first, split(u.second, 1).second);
    }
    P get(int l, int r) {
        return n->get(l, r);
    }
};
STree::Node STree::last_d = STree::Node();
STree::NP STree::last = &last_d;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    int n;
    cin >> n; n /= 2;
    using T = tuple<int, STree, STree>;
    struct Tcmp {
        const bool operator()(const T &a, const T &b) {
            return get<0>(a) > get<0>(b);
        }
    };
    priority_queue<T, vector<T>, Tcmp> que;


    auto tr_x = STree(), tr_y = STree();
    for (int i = 0; i < 2*n; i++) {
        int x;
        cin >> x;
        if (i % 2 == 0) {
            tr_x.merge(STree(x));
        } else {
            tr_y.merge(STree(x));
        }
    }

    que.push(T(tr_x.get(0, tr_x.sz()).first, tr_x, tr_y));

    V<int> res;
    while (que.size()) {
        int unko;
        STree tr1, tr2;
        tie(unko, tr1, tr2) = que.top(); que.pop();

        auto d = tr1.get(0, tr1.sz());
//        cout << d.first << " " << d.second << endl;
        res.push_back(d.first);
        auto e = tr2.get(d.second, tr2.sz());
        
//        cout << e.first << " " << e.second << endl;
        res.push_back(e.first);
        auto buf2 = tr1.split(e.second+1);
        auto buf1 = tr1.split(d.second).split(1);
        auto buf4 = tr2.split(e.second+1);
        tr2.split(tr2.sz()-1);
        auto buf3 = tr2.split(d.second);

        auto add = [&](STree& ta, STree& tb) {
            if (ta.sz() == 0) return;
//            cout << "add " << ta.get(0, ta.sz()).first << " " << ta.get(0, ta.sz()).second << endl;
            que.push(T(ta.get(0, ta.sz()).first, ta, tb));
        };
        add(tr1, tr2);
        add(buf3, buf1);
        add(buf2, buf4);
//        tr1.merge(buf3); tr1.merge(buf2);
//        tr2.merge(buf1); tr2.merge(buf4);
    }

    for (auto d: res) {
        cout << d << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 13620