//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#define debug(...) (cerr<<"'"<<__FUNCTION__<<"': "),fprintf(stderr,__VA_ARGS__)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
pair<int,int> mn0[800111],mn1[800111];
bool rev[800111];
int rmn[800111];
#define ls p<<1
#define rs p<<1|1
void pushdown(int p)
{
	if(rev[p])
	{
		rev[ls]^=1;
		swap(mn0[ls],mn1[ls]);
		rev[rs]^=1;
		swap(mn0[rs],mn1[rs]);
		rev[p]=0;
	}
	rmn[ls]=min(rmn[ls],rmn[p]);
	rmn[rs]=min(rmn[rs],rmn[p]);
}
void update(int p)
{
	mn0[p]=min(mn0[ls],mn0[rs]);
	mn1[p]=min(mn1[ls],mn1[rs]);
}
void reverse(int x,int y,int l,int r,int p=1)
{
//	cerr<<"reverse:"<<x<<","<<y<<" "<<l<<","<<r<<endl;
	if(x<=l&&r<=y)
	{
		rev[p]^=1;
		swap(mn0[p],mn1[p]);
		return;
	}
	pushdown(p);
	int m=l+r>>1;
	if(x<=m)reverse(x,y,l,m,ls);
	if(m<y)reverse(x,y,m+1,r,rs);
	update(p);
//	cerr<<l<<","<<r<<":"<<mn0[p].FF<<" "<<mn1[p].FF<<endl;
}
void changermn(int x,int y,int v,int l,int r,int p=1)
{
	if(x<=l&&r<=y)
	{
		rmn[p]=min(rmn[p],v);
		return;
	}
	pushdown(p);
	int m=l+r>>1;
	if(x<=m)changermn(x,y,v,l,m,ls);
	if(m<y)changermn(x,y,v,m+1,r,rs);
	update(p);
}
void change(int x,pair<int,int> v,int l,int r,int p=1)
{
	if(x==l&&x==r)
	{
		if(rev[p])mn0[p]=MP(Imx,Imx),mn1[p]=v;
		else mn0[p]=v,mn1[p]=MP(Imx,Imx);
		return;
	}
	pushdown(p);
	int m=l+r>>1;
	if(x<=m)change(x,v,l,m,ls);
	else change(x,v,m+1,r,rs);
	update(p);
//	cerr<<l<<","<<r<<" "<<mn0[p].FF<<" "<<mn1[p].FF<<endl;
}
pair<int,int> query0(int x,int y,int l,int r,int p=1)
{
	if(x<=l&&r<=y)return mn0[p];
	pushdown(p);
	int m=l+r>>1;
	if(x<=m&&m<y)return min(query0(x,y,l,m,ls),query0(x,y,m+1,r,rs));
	else if(x<=m)return query0(x,y,l,m,ls);
	else return query0(x,y,m+1,r,rs);
}
pair<int,int> query1(int x,int y,int l,int r,int p=1)
{
	if(x<=l&&r<=y)return mn1[p];
	pushdown(p);
	int m=l+r>>1;
	if(x<=m&&m<y)return min(query1(x,y,l,m,ls),query1(x,y,m+1,r,rs));
	else if(x<=m)return query1(x,y,l,m,ls);
	else return query1(x,y,m+1,r,rs);
}
int queryrmn(int x,int y,int l,int r,int p=1)
{
	if(x<=l&&r<=y)return rmn[p];
	pushdown(p);
	int m=l+r>>1;
	if(x<=m&&m<y)return min(queryrmn(x,y,l,m,ls),queryrmn(x,y,m+1,r,rs));
	else if(x<=m)return queryrmn(x,y,l,m,ls);
	else return queryrmn(x,y,m+1,r,rs);
}
void dfs(int l,int r,int p=1)
{
	cerr<<l<<","<<r<<" "<<mn0[p].FF<<" "<<mn1[p].FF<<endl;
	if(l==r)return;
	dfs(l,(l+r)>>1,ls);
	dfs(((l+r)>>1)+1,r,rs);
	
}
int n,a[200111];
int main()
{
	memset(rmn,63,sizeof(rmn));
	geti(n);
	for(int i=1;i<=n;i++)
	{
		int x;
		geti(x);
		a[i]=x;
		change(i,MP(x,i),1,n);
	}
	for(int i=2;i<=n;i+=2)reverse(i,i,1,n);
//	dfs(1,n,1);
	for(int i=1;i<=n;i+=2)
	{
		int x=query0(1,n,1,n).SS;
		int tr=min(queryrmn(x,x,1,n),n);
//		cerr<<"tr="<<tr<<endl;
		int y=query1(x,tr,1,n).SS;
		putii(a[x],a[y]);
		if(x+1<y)reverse(x+1,y-1,1,n);
		change(x,MP(Imx,Imx),1,n);
		change(y,MP(Imx,Imx),1,n);
		if(x>1)changermn(1,x-1,x-1,1,n);
		if(x+1<y)changermn(x+1,y-1,y-1,1,n);
	}
	return 0;
}

Measured memory_bytes: 17920