#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

using Int = long long;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
    using F = function<T(T,T)>;
    using G = function<T(T,E)>;
    using H = function<E(E,E)>;
    int n,height;
    F f;
    G g;
    H h;
    T ti;
    E ei;
    vector<T> dat;
    vector<E> laz;
    SegmentTree(F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){}
    
    void init(int n_){
        n=1;height=0;
        while(n<n_) n<<=1,height++;
        dat.assign(2*n,ti);
        laz.assign(2*n,ei);
    }
    void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }
    inline T reflect(int k){
        return laz[k]==ei?dat[k]:g(dat[k],laz[k]);
    }
    inline void eval(int k){
        if(laz[k]==ei) return;
        laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
        laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
        dat[k]=reflect(k);
        laz[k]=ei;
    }
    inline void thrust(int k){
        for(int i=height;i;i--) eval(k>>i);
    }
    inline void recalc(int k){
        while(k>>=1)
            dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));
    }
    void update(int a,int b,E x){
        thrust(a+=n);
        thrust(b+=n-1);
        for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
            if(l&1) laz[l]=h(laz[l],x),l++;
            if(r&1) --r,laz[r]=h(laz[r],x);
        }
        recalc(a);
        recalc(b);
    }
    void set_val(int a,T x){
        thrust(a+=n);
        dat[a]=x;laz[a]=ei;
        recalc(a);
    }
    T query(int a,int b){
        thrust(a+=n);
        thrust(b+=n-1);
        T vl=ti,vr=ti;
        for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
            if(l&1) vl=f(vl,reflect(l++));
            if(r&1) vr=f(reflect(--r),vr);
        }
        return f(vl,vr);
    }
};
//END CUT HERE



int main(){
    ll n;
    cin>>n;
    vector<ll> A(n);
    for(auto &I:A){cin>>I; I--;}
    
    using P = pair<pll, pll>;
    auto f=[](P a,P b){return P(min(a.F,b.F),min(a.S,b.S));};
    auto g=[](P a,pair<bool,bool> b){
        if(b.F){swap(a.F,a.S);}
        if(b.S){a.F=a.S={E,E};}
        return a;
    };
    auto h=[](pair<bool,bool> a,pair<bool,bool> b){return pair<bool,bool>(a.F^b.F,a.S|b.S);};
    auto func=[](Int a,Int b){return min(a,b);};
    SegmentTree<P,pair<bool,bool>> T(f,g,h,{{E,E},{E,E}},{false,false});
    vector<P> S(n,{{E,E},{E,E}});
    for(int i=0;i<n;i++){
        if(i&1){S[i].S={A[i],i};}
        else{S[i].F={A[i],i};}
    }
    T.build(S);
    SegmentTree<Int,Int> nx(func,func,func,E,E);
    nx.build(vector<Int>(n,n));
    vector<ll> ans;
    for(int i=0;i<n;i+=2){
        //cout<<i<<endl;
        P ret=T.query(0,n);
        ans.push_back(ret.F.F);
        ll w=ret.F.S;
        ll x=nx.query(w,n);
        ret=T.query(w,x);
        ans.push_back(ret.S.F);
        ll w2=ret.S.S;
        //cout<<w<<" "<<w2<<" "<<x<<endl;
        nx.update(w,w+1,w);
        nx.update(w2,w2+1,w2);
        T.update(w,w2,{true,false});
        T.update(w,w+1,{false,true});
        T.update(w2,w2+1,{false,true});
    }
    for(int i=0;i<n;i++){cout<<ans[i]+1<<(i+1==n?"\n":" ");}
    
    
    
    return 0;
}


Measured memory_bytes: 38628