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<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=200000+19;
const int oo=(1<<30)-1;

int mn[2][20][N];
int A[2][N];
int Lg[N];
int n;

struct node{
	int l,r,t;
	bool operator < (const node &B) const{
		return A[t&1][t]>A[B.t&1][B.t];
	}
};priority_queue<node> Q;

int cmp(int t,int x,int y){
	return A[t][x]<A[t][y]?x:y;
}
int calmn(int t,int l,int r){
	int _=Lg[r-l+1];
	return cmp(t,mn[t][_][l],mn[t][_][r-(1<<_)+1]);
}
void Push(int l,int r){
	if (l>r) return;
	assert((r-l+1)%2==0);
	Q.push((node){l,r,calmn(l&1,l,r)});
}

int main(){
	Lg[1]=0;
	For(i,2,N) Lg[i]=Lg[i>>1]+1;
	For(i,0,2){
		For(j,0,N){
			A[i][j]=oo;
			mn[i][0][j]=j;
		}
	}
	n=IN();
	For(i,1,n+1) A[i&1][i]=IN();
	For(t,0,2){
		For(x,1,20){
			for (int i=1;i+(1<<x)-1<=n;i++){
				mn[t][x][i]=cmp(t,mn[t][x-1][i],mn[t][x-1][i+(1<<x-1)]);
			}
		}
	}
	Push(1,n);
	while (!Q.empty()){
		node P=Q.top();Q.pop();
		printf("%d ",A[P.t&1][P.t]);
		int w=calmn(P.r&1,P.t+1,P.r);
		printf("%d ",A[w&1][w]);
		Push(P.l,P.t-1);
		Push(P.t+1,w-1);
		Push(w+1,P.r);
	}
	puts("");
}