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 <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1e9 + 9;

int n, p[200000];

struct RMQ {
	int n;
	vector<pair<int, int>> t;
	RMQ(int _n) {
		n = _n;
		t.resize(2 * n, {INF, INF});
	}
	void upd(int v, int a, int b) {
		t[v += n] = {a, b};
		for(v >>= 1; v; v >>= 1)
			t[v] = min(t[v * 2], t[v * 2 + 1]);
	}
	pair<int, int> get(int l, int r) {
		pair<int, int> res = {INF, INF};
		for(l += n, r += n; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) {
			if(l & 1) res = min(res, t[l]);
			if(!(r & 1)) res = min(res, t[r]);
		}
		return res;
	}
};

RMQ odd(200000), even(200000);

struct seg {
	int l, r;
	int f;
	bool operator < (const seg &x) const {
		return f < x.f;
	}
};

set<seg> setik;

inline void ins(int l, int r) {
	if(l % 2 == 0) setik.insert({l, r, even.get(l, r).first});
	else setik.insert({l, r, odd.get(l, r).first});
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> p[i];
		if(i % 2 == 0) even.upd(i, p[i], i);
		else odd.upd(i, p[i], i);
	}
	setik.insert({0, n - 1, even.get(0, n - 1).first});
	for(int i = 0; i < n / 2; i++) {
		seg cur = *setik.begin();
		setik.erase(setik.begin());
		pair<int, int> f, s;
		if(cur.l % 2 == 0) {
			f = even.get(cur.l, cur.r);
			s = odd.get(f.second + 1, cur.r);
		} else {
			f = odd.get(cur.l, cur.r);
			s = even.get(f.second + 1, cur.r);
		}
		cout << f.first << ' ' << s.first << ' ';
		if(f.second != cur.l) ins(cur.l, f.second - 1);
		if(f.second + 1 != s.second) ins(f.second + 1, s.second - 1);
		if(s.second != cur.r) ins(s.second + 1, cur.r);
	}
}