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<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int p[210000];
int inv[210000];
int segtree[2][524288];
int ret[210000];
int query(int a,int b,int c,int d,int e,int f){
	if(d<a||b<c)return mod;
	else if(c<=a&&b<=d)return segtree[f][e];
	return min(query(a,(a+b)/2,c,d,e*2,f),query((a+b)/2+1,b,c,d,e*2+1,f));
}
void update(int a,int b,int c){
	a+=262144;
	while(a){
		segtree[c][a]=min(segtree[c][a],b);
		a/=2;
	}
}
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){scanf("%d",p+i);p[i]--;}
	for(int i=0;i<2;i++)for(int j=0;j<524288;j++)segtree[i][j]=mod;
	for(int i=0;i<a;i++)inv[p[i]]=i;
	for(int i=0;i<a;i++){
		update(i,p[i],i%2);
	}
	priority_queue<pair<int,pair<int,int> > >Q;
	Q.push(make_pair(-query(0,262143,0,a-1,1,0),make_pair(0,a)));
	int ind=0;
	while(Q.size()){
		int cost=-Q.top().first;
		int L=Q.top().second.first;
		int R=Q.top().second.second;
		Q.pop();
		int at=inv[cost];
		int q=query(0,262143,at,R-1,1,(at+1)%2);
		int at2=inv[q];
		ret[ind++]=cost;
		ret[ind++]=q;
		if(L<at){
			Q.push(make_pair(-query(0,262143,L,at-1,1,L%2),make_pair(L,at)));
		}
		if(at+1<at2){
			Q.push(make_pair(-query(0,262143,at+1,at2-1,1,(at+1)%2),make_pair(at+1,at2)));
		}
		if(at2+1<R){
			Q.push(make_pair(-query(0,262143,at2+1,R-1,1,(at2+1)%2),make_pair(at2+1,R)));
		}
	}
	for(int i=0;i<a;i++){
		if(i)printf(" ");
		printf("%d",ret[i]+1);
	}
	printf("\n");
}