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 <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <queue>

using namespace std;
typedef long long LL;
#define ls rt<<1
#define rs rt<<1|1
const int maxn = 200005;

int p[maxn],pos[maxn],n,N;
struct ST {
	int mi[maxn*4];
	int query(int rt,int L,int R,int l,int r)
	{
		if (L>=l&&R<=r) return mi[rt];
		int mid=L+R>>1,res=1<<30;
		if (l<=mid) res=min(res,query(ls,L,mid,l,r));
		if (r>mid) res=min(res,query(rs,mid+1,R,l,r));
		return res;
	}
	void build(int rt,int L,int R,int o)
	{
		if (L>=R) {
			mi[rt]=p[L<<1|o];return ;
		}
		int mid=L+R>>1;
		build(ls,L,mid,o);
		build(rs,mid+1,R,o);
		mi[rt]=min(mi[ls],mi[rs]);
	}
}od,ev;
struct node {
	int l,r,sl,sr;
	bool operator<(const node &v) const {
		return p[v.sl]<p[sl];
	}
};
priority_queue<node> Q;
void insert(int l,int r) {
	int sl,sr;
	if (l>=r) return ;
	if (l&1) {
		sl=pos[od.query(1,0,N,l>>1,r-1>>1)];
		sr=pos[ev.query(1,0,N,sl+1>>1,r>>1)];
	}
	else {
		sl=pos[ev.query(1,0,N,l>>1,r-1>>1)];
		sr=pos[od.query(1,0,N,sl+1>>1,r>>1)];
	}
	Q.push((node){l,r,sl,sr});
}
int main()
{
	#ifdef Amberframe
		freopen("arc080e.in","r",stdin);
		freopen("arc080e.out","w",stdout);
	#endif
	scanf("%d",&n);N=(n>>1)-1;
	for (int i=0;i<n;i++) scanf("%d",&p[i]),pos[p[i]]=i;
	ev.build(1,0,N,0);od.build(1,0,N,1);
	
	insert(0,n-1);
	while (!Q.empty()) {
		node w=Q.top();Q.pop();
		printf("%d %d ",p[w.sl],p[w.sr]);
		insert(w.l,w.sl-1);
		insert(w.sl+1,w.sr-1);
		insert(w.sr+1,w.r);
	}
	return 0;
}