Problem: 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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N=200005;
int n,a[N],t[2][N<<2];
void update(int o,int rt,int L,int R,int pos){
	if (a[pos]<a[t[o][rt]])
		t[o][rt]=pos;
	if (L==R)
		return;
	int mid=(L+R)>>1,ls=rt<<1,rs=ls|1;
	if (pos<=mid)
		update(o,ls,L,mid,pos);
	else
		update(o,rs,mid+1,R,pos);
}
int query(int o,int rt,int L,int R,int xL,int xR){
	if (L>xR||R<xL)
		return 0;
	if (xL<=L&&R<=xR)
		return t[o][rt];
	int mid=(L+R)>>1,ls=rt<<1,rs=ls|1;
	int Lans=query(o,ls,L,mid,xL,xR);
	int Rans=query(o,rs,mid+1,R,xL,xR);
	return a[Lans]<a[Rans]?Lans:Rans;
}
struct seg{
	int L,R,v;
	seg(){}
	seg(int _L,int _R){
		L=_L,R=_R,v=L>R?0:query(L&1,1,1,n,L,R);
	}
	friend bool operator < (seg A,seg B){
		return a[A.v]<a[B.v];
	}
};
int scnt=0;
set <seg> S;
int main(){
	scanf("%d",&n);
	a[0]=n+1;
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		update(i&1,1,1,n,i);
	}
	S.clear();
	S.insert(seg(1,n));
	for (int i=1;i<=n/2;i++){
		seg now=*S.begin();
		S.erase(S.begin());
		int L=now.L,R=now.R;
		int Lmid=now.v,Rmid=query((Lmid&1)^1,1,1,n,Lmid,R);
		printf("%d %d ",a[Lmid],a[Rmid]);
		S.insert(seg(L,Lmid-1));
		S.insert(seg(Lmid+1,Rmid-1));
		S.insert(seg(Rmid+1,R));
	}
	return 0;
}