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;
#define _0 first
#define _1 second
typedef pair<int,int>pii;
typedef pair<pair<pii,pii>,pii>pp_p;

int N;
const int B=1<<18;
pii s[2*B];

pii d(int i){
	if(i<B){
		return s[i]=min(d(i*2-i%2),d(i*2+2-i%2));
	}else{
		return s[i];
	}
}

pp_p rmq(pii lr){
	auto f=[](int l,int r){
		pii t=s[l+=B],u=s[r+=B];
		for(;l/4<r/4;l=l/4*2+l%2,r=r/4*2+r%2){
			t=l&2?t:min(t,s[l+2]);
			u=r&2?min(s[r-2],u):u;
		}
		return min(t,u);
	};
	pii x,y;
	x=f(lr._0,lr._1-2);
	y=f(x._1+1,lr._1-1);
	return{{x,y},lr};
}

int main(){
	for(int i=2;i<2*B;++i){
		s[i]={B,B};
	}
	cin>>N;
	for(int i=0;i<N;++i){
		int p;
		cin>>p;
		s[B+i]={p,i};
	}
	d(2);
	d(3);
	priority_queue<pp_p,vector<pp_p>,greater<pp_p>>pq;
	pq.push(rmq({0,N}));
	while(pq.size()){
		auto a=pq.top();
		pq.pop();
		cout<<" "<<a._0._0._0<<" "<<a._0._1._0;
		for(auto b:(vector<pii>){{a._1._0,a._0._0._1},{a._0._0._1+1,a._0._1._1},{a._0._1._1+1,a._1._1}}){
			if(b._0<b._1){
				pq.push(rmq(b));
			}
		}
	}
}
