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;
typedef pair<int,int> pii;
priority_queue<pii,vector<pii>,greater<pii> >q;
const int maxn=2e5+10;
int p[maxn],Mi[maxn][20][2],Log[maxn],deg[maxn],in[maxn];
int hea[maxn],to[maxn<<1],nxt[maxn<<1],tot,cnt;
pii v[maxn];
int get(int l,int r,int f) {
	int L=Log[r-l+1];
	return min(Mi[l][L][f],Mi[r-(1<<L)+1][L][f]);
}
void add(int a,int b) {
	if(!a||!b)return;
	deg[b]++;
	nxt[++tot]=hea[a];
	hea[a]=tot;
	to[tot]=b;
}
int dfs(int l,int r) {
	if(r<l)return 0;
	int a=get(l,r,l&1),b=get(p[a]+1,r,r&1),now=++cnt;
	in[a]=now;
	v[now].first=a;
	v[now].second=b;
	add(now,dfs(l,p[a]-1));
	add(now,dfs(p[a]+1,p[b]-1));
	add(now,dfs(p[b]+1,r));
	return now;
}
int main() {
	memset(Mi,0x3f,sizeof(Mi));
	int n,a;
	scanf("%d",&n);
	Log[1]=0;
	for(int i=2;i<=n;i++)
		Log[i]=Log[i>>1]+1;
	for(int i=1;i<=n;i++) {
		scanf("%d",&a);
		Mi[i][0][i&1]=a;
		p[a]=i;
	}
	for(int i=1;i<20;i++)
		for(int j=1;j+(1<<i)-1<=n;j++) {
			Mi[j][i][0]=min(Mi[j][i-1][0],Mi[j+(1<<(i-1))][i-1][0]);
			Mi[j][i][1]=min(Mi[j][i-1][1],Mi[j+(1<<(i-1))][i-1][1]);
		}
	dfs(1,n);
	q.push(v[1]);
	while(!q.empty()) {
		pii x=q.top();
		q.pop();
		printf("%d %d ",x.first,x.second);
		for(int i=hea[in[x.first]];i;i=nxt[i]) {
			deg[to[i]]--;
			if(!deg[to[i]])q.push(v[to[i]]);
		}
	}
	puts("");
	return 0;
}