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=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;
}