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 <set>

const int Z = 1<<18;

struct node{
	node(){
		sz = 0; a[0] = a[1] = 0x7fffffff;
	}
	node(int x, int i){
		if (x == 0x7fffffff) sz = 0, a[0] = a[1] = x;
		else sz = 1, a[0] = x, a[1] = 0x7fffffff, p[0] = i;
	}
	int sz,a[2],p[2];

	node operator +(const node &t)const{
		node r = (*this);
		for (int k=0;k<2;k++){
			if (r.a[k] > t.a[(k + r.sz)%2]){
				r.a[k] = t.a[(k + r.sz)%2];
				r.p[k] = t.p[(k + r.sz)%2];
			}
		}
		r.sz += t.sz;
		return r;
	}
}IT[Z*2];

void in(int x)
{
	x += Z;
	IT[x] = node(); x /= 2;
	while (x){
		IT[x] = IT[x*2] + IT[x*2+1];
		x /= 2;
	}
}

node out(int l, int r)
{
	node u,v;
	l += Z; r += Z;
	while (l <= r){
		if (l & 1) u = u + IT[l++];
		if (~r & 1) v = IT[r--] + v;
		l /= 2; r /= 2;
	} if (l == r) u = u + IT[l];
	return u + v;
}

int main()
{
	int N; scanf ("%d",&N);
	for (int i=0;i<N;i++){
		int x; scanf ("%d",&x);
		IT[i+Z] = node(x,i);
	}
	for (int i=Z-1;i>=1;i--) IT[i] = IT[i*2] + IT[i*2+1];

	std::set<int> div; div.insert(N);
	for (int i=N/2;i>=1;i--){
		node p = out(0,N-1);
		in(p.p[0]);
		int lim = *div.lower_bound(p.p[0]);
		div.insert(p.p[0]);
		node q = out(p.p[0],lim-1);
		in(q.p[0]);
		div.insert(q.p[0]);
		printf ("%d %d%c",p.a[0],q.a[0],i>1?' ':'\n');
	}

	return 0;
}