#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define size(n) ( int( n.size() ) )
#define sqr(n) ( (n) * (n) )
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 5;
int tclr[N*4], t[N*4][2], n, p[N*2], a[N*2], pos[N];

void build( int v, int tl, int tr ){
    if ( tl == tr ){
        if ( tl % 2 == 0 ){
            t[v][0] = p[tl];
            t[v][1] = 1e9;
        }
        else{
            t[v][0] = 1e9;
            t[v][1] = p[tl];
        }
        return;
    }
    int tm = ( tl + tr ) >> 1;
    build( (v<<1), tl, tm );
    build( (v<<1) + 1, tm + 1, tr );
    t[v][0] = min( t[(v<<1)][0], t[(v<<1)+1][0] );
    t[v][1] = min( t[(v<<1)][1], t[(v<<1)+1][1] );
}

void add( int& x ){
    x++;
    if ( x == 2 ){
        x = 0;
    }
}

void push( int v ){
    if ( !tclr[v] ){
        return;
    }
    add( tclr[(v<<1)] );
    add( tclr[(v<<1)+1] );
    swap( t[(v<<1)][0], t[(v<<1)][1] );
    swap( t[(v<<1)+1][0], t[(v<<1)+1][1] );
    tclr[v] = 0;
}

int get( int v, int tl, int tr, int l, int r, int tp ){
    if ( ( l == tl ) && ( r == tr ) ){
        return t[v][tp];
    }
    push(v);
    int tm = ( tl + tr ) >> 1;
    if ( r <= tm ){
        return get( (v<<1), tl, tm, l, r, tp );
    }
    if ( l >= tm + 1 ){
        return get( (v<<1) + 1, tm + 1, tr, l, r, tp );
    }
    return min( get( (v<<1), tl, tm, l, tm, tp ), get( (v<<1) + 1, tm + 1, tr, tm + 1, r, tp ) );
}

void update( int v, int tl, int tr, int l, int r ){
    if ( l > r ){
        return;
    }
    if ( ( l == tl ) && ( r == tr ) ){
        add( tclr[v] );
        swap( t[v][0], t[v][1] );
        return;
    }
    push(v);
    int tm = ( tl + tr ) >> 1;
    if ( r <= tm ){
        update( (v<<1), tl, tm, l, r );
    }
    else
    if ( l >= tm + 1 ){
        update( (v<<1) + 1, tm + 1, tr, l, r );
    }
    else{
        update( (v<<1), tl, tm, l, tm );
        update( (v<<1) + 1, tm + 1, tr, tm + 1, r );
    }
    t[v][0] = min( t[(v<<1)][0], t[(v<<1)+1][0] );
    t[v][1] = min( t[(v<<1)][1], t[(v<<1)+1][1] );
}

void upId( int v, int tl, int tr, int idx ){
    if ( tl == tr ){
        t[v][0] = 1e9;
        t[v][1] = 1e9;
        return;
    }
    push(v);
    int tm = ( tl + tr ) >> 1;
    if ( idx <= tm ){
        upId( (v<<1), tl, tm, idx );
    }
    else{
        upId( (v<<1) + 1, tm + 1, tr, idx );
    }
    t[v][0] = min( t[(v<<1)][0], t[(v<<1)+1][0] );
    t[v][1] = min( t[(v<<1)][1], t[(v<<1)+1][1] );
}

set < int > s;
set < int > :: iterator it;

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    scanf("%d",&n);
    int sz = 1;
    while( sz < n ){
        sz *= 2;
    }
    for ( int i = 1; i <= n; i++ ){
        scanf("%d",&p[i]);
        pos[ p[i] ] = i;
    }
    for ( int i = n + 1; i <= sz; i++ ){
        p[i] = 1e9;
    }
    build( 1, 1, sz );
    int len = 0;
    for ( int i = 1; i <= n / 2; i++ ){
        int x = get( 1, 1, sz, 1, n, 1 );
        int idx = pos[x];
        it = s.upper_bound( idx );
        int rb = n;
        if ( it != s.end() ){
            rb = (*it) - 1;
        }
        int y = get( 1, 1, sz, idx + 1, rb, 0 );
        int idy = pos[y];
        a[++len] = x;
        a[++len] = y;
        update( 1, 1, sz, idx + 1, idy - 1 );
        upId( 1, 1, sz, idx );
        upId( 1, 1, sz, idy );
        s.insert(idx);
        s.insert(idy);
    }
    for ( int i = 1; i <= n; i++ ){
        printf("%d ",a[i]);
    }
    return 0;
}




Measured memory_bytes: 22784