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;
 
 
struct SegmentTree{
    vector<int> Seg;
	int n;
 
	void build(vector<int>& v, int m){
		n = m;
        Seg = vector<int> (4*n,1e6);
		build(v, 1, 0, n);
	}
	void build( vector<int>& v, int id,int left, int right){
		if(left + 1 >= right){
			Seg[id] = v[left];
			return;
		}
		int mid = (left + right)/2;
		build(v, id * 2, left, mid);
		build(v, id * 2 + 1, mid, right);
		Seg[id] = min(Seg[id*2],Seg[id*2 + 1]);
	}
 
	int find(int x, int y){
		return find(x, y, 1, 0, n);
	}
	int find(int x, int y, int id, int left, int right){
		if(left >= y or right <= x){
			return 1e6;
		}
		if(left >= x and right <= y){
			return Seg[id];
		}
		int mid = (left + right)/2;
		return min(find(x, y, 2*id, left, mid), find(x, y, 2*id + 1, mid, right));
	}
};
SegmentTree S[2];
 
struct obj {
	int x,y,i;
	bool operator < (const obj& o) const {
		return x > o.x;
	}
};

int pos[200010];
int s = 0;
vector<obj> adj[200010];
priority_queue<obj> pq;
	
void getans(int l, int r, int p, int par) {
	if(l + 1 >= r) return;
	int curNode = s++;
	int x = S[p].find(l,r);
	int px = pos[x];
	int y = S[p^1].find(px + 1, r);
	int py = pos[y];

	if(par != -1) {
		adj[par].push_back({x,y,curNode});
	}
	else {
		pq.push({x,y,curNode});
	}
	
	getans(l, px, p, par);
	getans(px + 1, py, p^1, curNode);
	getans(py + 1, r, p, par);
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> odd(n, 1e6), even(n, 1e6);
	for(int i = 0; i < n; ++i){
		int x;
		cin >> x;
		pos[x] = i;
		if(i&1) even[i] = x;
		else odd[i] = x;
	}
 
	S[0].build(odd, n);
	S[1].build(even, n);
	getans(0,n,0,-1);
 
	int ans[n];

	while(pq.size()) {
		auto x = pq.top();
		pq.pop();
		cout << x.x << ' ' << x.y << ' ';
		for(auto i : adj[x.i]) pq.push(i);
	}

}
