Let N be a positive even number.

We have a permutation of (1, 2, ..., N), p = (p_1, p_2, ..., p_N). Snuke is constructing another permutation of (1, 2, ..., N), q, following the procedure below.

First, let q be an empty sequence. Then, perform the following operation until p becomes empty:

* Select two adjacent elements in p, and call them x and y in order. Remove x and y from p (reducing the length of p by 2), and insert x and y, preserving the original order, at the beginning of q.



When p becomes empty, q will be a permutation of (1, 2, ..., N).

Find the lexicographically smallest permutation that can be obtained as q.

Constraints

* N is an even number.
* 2 ≤ N ≤ 2 × 10^5
* p is a permutation of (1, 2, ..., N).

Input

Input is given from Standard Input in the following format:


N
p_1 p_2 ... p_N


Output

Print the lexicographically smallest permutation, with spaces in between.

Examples

Input

4
3 2 4 1


Output

3 1 2 4


Input

2
1 2


Output

1 2


Input

8
4 6 3 2 8 5 7 1


Output

3 1 2 7 4 6 8 5
#include<bits/stdc++.h>
using namespace std;

const int N=200100;
int ch[N][2],mn1[N],fa[N],mn2[N],a[N],sz[N],n,rt;
bool gs(int x){return ch[fa[x]][1]==x;}
void ps(int x){
	int lc=ch[x][0],rc=ch[x][1];
	sz[x]=sz[lc]+sz[rc]+1;
	mn1[x]=mn1[lc];mn2[x]=mn2[lc];
	if(sz[lc]&1){
		mn1[x]=min(mn1[x],mn1[rc]);
		mn2[x]=min(mn2[x],min(mn2[rc],a[x]));
	}else{
		mn1[x]=min(mn1[x],min(mn2[rc],a[x]));
		mn2[x]=min(mn2[x],mn1[rc]);
	}
}


void rot(int x){
	int o=fa[x],k=gs(x);
	fa[ch[o][k]=ch[x][!k]]=o;
	fa[x]=fa[o];
	if(fa[o])ch[fa[o]][gs(o)]=x;
	fa[ch[x][!k]=o]=x;ps(o);
}

void splay(int x,int y=0){
	for(;fa[x]!=y;rot(x))
		if(fa[fa[x]]!=y)rot(gs(x)^gs(fa[x])?x:fa[x]);
	ps(x);if(!y)rt=x;else ps(y);
}

int merge(int x,int y){
	if(!x||!y)return x+y;
	for(;ch[x][1];x=ch[x][1]);splay(x);
	ch[x][1]=y;fa[y]=x;ps(x);return x;
}
set<int>S;
int b[N];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	mn1[0]=mn2[0]=n+1;
	for(int i=1;i<=n;++i){
		cin>>a[i];b[a[i]]=i;
		sz[i]=1;mn1[i]=a[i];mn2[i]=n+1;
		rt=merge(rt,i);
	}
	S.insert(mn1[rt]);
	for(int i=1;i<=n;i+=2){
		int x=b[*S.begin()];S.erase(S.begin());splay(x);
		int y=b[mn1[ch[x][1]]];splay(y,x);
		cout<<a[x]<<' '<<a[y]<<" \n"[i==n-1];
		int u=ch[x][0],v=ch[y][0],w=ch[y][1];
		fa[u]=fa[v]=fa[w]=0;
		if(u)S.insert(mn1[u]);
		if(v)S.insert(mn1[v]);
		if(w)S.insert(mn1[w]);
	}
	return 0;
}
