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 <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)

const int INF=0x3f3f3f3f;
const int N=400005;

int w[N],n;

struct data {
	int l,r,w1,w2;
	bool operator <(data b) const {
		return (w[w1]==w[b.w1])?(w[w2]>w[b.w2]):(w[w1]>w[b.w1]);
	}
} ;

struct RMQ {
	int rec[18][N],lg[N];

	void pre() {
		rep(i,2,N-1) lg[i]=lg[i>>1]+1;
		rep(j,1,lg[n]) {
			rep(i,1,n-(1<<j)+1) {
				if (w[rec[j-1][i]]>w[rec[j-1][i+(1<<j-1)]]) {
					rec[j][i]=rec[j-1][i+(1<<j-1)];
				} else rec[j][i]=rec[j-1][i];
			}
		}
	}

	int ask(int l,int r) {
		int t=lg[r-l+1];
		if (w[rec[t][l]]<w[rec[t][r-(1<<t)+1]]) return rec[t][l];
		else return rec[t][r-(1<<t)+1];
	}
} T[2];

std:: priority_queue <data> heap;

int read() {
	int x=0,v=1; char ch=getchar();
	for (;ch<'0'||ch>'9';v=(ch=='-')?(-1):v,ch=getchar());
	for (;ch<='9'&&ch>='0';x=x*10+ch-'0',ch=getchar());
	return x*v;
}

int main(void) {
	n=read(),w[0]=INF;
	rep(i,1,n) {
		w[i]=read();
		T[i&1].rec[0][i]=i;
		T[!(i&1)].rec[0][i]=0;
	}
	T[0].pre(),T[1].pre();
	int p1=T[1].ask(1,n-1);
	int p2=T[0].ask(p1+1,n);
	heap.push((data) {1,n,p1,p2});
	for (int i=1;i*2<=n;++i) {
		data top=heap.top(); heap.pop();
		int l=top.l,r=top.r,w1=top.w1,w2=top.w2,wjp;
		printf("%d %d ", w[top.w1],w[top.w2]);
		if (w1>l+1) {
			wjp=l&1;
			p1=T[wjp].ask(l,w1-2);
			p2=T[!wjp].ask(p1+1,w1-1);
			heap.push((data) {l,w1-1,p1,p2});
		}
		if (w2+1<r) {
			wjp=(w2+1)&1;
			p1=T[wjp].ask(w2+1,r-1);
			p2=T[!wjp].ask(p1+1,r);
			heap.push((data) {w2+1,r,p1,p2});
		}
		if (w1+1<w2) {
			wjp=(w1+1)&1;
			p1=T[wjp].ask(w1+1,w2-2);
			p2=T[!wjp].ask(p1+1,w2-1);
			heap.push((data) {w1+1,w2-1,p1,p2});
		}
	} puts("");
	return 0;
}