#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int n,m,p[N],pos[N],a[N];
struct segment_tree{
	int Min[N];
	#define lc x<<1
	#define rc x<<1|1
	void init(int x,int l,int r){
		if (l==r) return void(Min[x]=a[l]);
		int mid=(l+r)>>1;
		init(lc,l,mid);
		init(rc,mid+1,r);
		Min[x]=min(Min[lc],Min[rc]);
	}
	int query(int x,int l,int r,int L,int R){
		if (l>=L&&r<=R) return Min[x];
		int mid=(l+r)>>1,ans=1e9;
		if (L<=mid) ans=min(ans,query(lc,l,mid,L,R));
		if (R>mid) ans=min(ans,query(rc,mid+1,r,L,R));
		return ans;
	}
}T[2];
struct sit{
	int l,r,v;
	sit(int L,int R){l=L;r=R;v=T[l&1].query(1,1,m,(l+1)/2,(l+1)/2+(r-l)/2);}
};
struct cmp{bool operator () (sit x,sit y){return x.v>y.v;}};
priority_queue<sit,vector<sit>,cmp> Q;
int main()
{
	scanf("%d",&n);m=n>>1;
	for (int i=1;i<=n;i++) scanf("%d",&p[i]),pos[p[i]]=i;
	for (int i=1;i<=m;i++) a[i]=p[2*i-1];
	T[1].init(1,1,m);
	for (int i=1;i<=m;i++) a[i]=p[2*i];
	T[0].init(1,1,m);
	Q.push(sit(1,n));
	while (!Q.empty()){
		sit now=Q.top();Q.pop();
		int l=now.l,r=now.r,p1=now.v;
		int p2=T[r&1].query(1,1,m,(pos[p1]+2)>>1,(r+1)>>1);
		printf("%d %d ",p1,p2);
		p1=pos[p1];p2=pos[p2];
		if (l<p1) Q.push(sit(l,p1-1));
		if (p1+1<p2) Q.push(sit(p1+1,p2-1));
		if (p2<r) Q.push(sit(p2+1,r));
	}
	return 0;
}