#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> *i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> " " >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

struct RMQ {
    int n;
    bool odd;
    vector<pii> data;
    RMQ() {}
    RMQ(int n_, bool odd_) {
        n=1;
        odd=odd_;
        while(n<n_) n<<=1;
        data.resize(n<<1,{INF,-1});
    }
    void update(int i,int x) {
        if(i%2!=odd) return;

        int idx=i;
        i+=n-1;
        data[i]={x,idx};
        while(i>0) {
            i=(i-1)/2;
            data[i]=min(data[i*2+1],data[i*2+2]);
        }
    }
    pii query(int a,int b) {
        return query(a,b,0,0,n);
    }
    pii query(int a,int b,int k,int l,int r) {
        if(r<=a or b<=l) return {INF,-1};
        if(a<=l and r<=b) return data[k];
        pii ml=query(a,b,k*2+1,l,(r+l)/2);
        pii mr=query(a,b,k*2+2,(r+l)/2,r);
        return min(ml,mr);
    }
};
signed main() {
    int n;
    cin>>n;
    vector<int> a(n);
    cin>>a;

    RMQ sgt[2];
    sgt[0]=RMQ(n,0);
    sgt[1]=RMQ(n,1);
    REP(i,n) {
        sgt[0].update(i,a[i]);
        sgt[1].update(i,a[i]);
    }

    vector<pii> ans;

    priority_queue<pair<int,pii>,vector<pair<int,pii>>,greater<pair<int,pii>>> pq;
    pq.push({sgt[0].query(0,n).first,{0,n}});
    while(!pq.empty()) {
        pii r=pq.top().second; pq.pop();
        pii X=sgt[r.first%2].query(r.first,r.second);
        pii Y=sgt[!(r.first%2)].query(X.second+1,r.second);
        ans.push_back({X.first,Y.first});
        
        pii L={r.first,X.second};
        pii M={X.second+1,Y.second};
        pii R={Y.second+1,r.second};
        if(L.second-L.first>1) pq.push({sgt[L.first%2].query(L.first,L.second).first,L});
        if(M.second-M.first>1) pq.push({sgt[M.first%2].query(M.first,M.second).first,M});
        if(R.second-R.first>1) pq.push({sgt[R.first%2].query(R.first,R.second).first,R});
    }

    REP(i,n/2) {
        cout<<ans[i].first<<" "<<ans[i].second;
        if(i==n/2-1) cout<<endl;
        else cout<<" ";
    }
    return 0;
}


Measured memory_bytes: 22304