#include<bits/stdc++.h>
using namespace std;
#define MAXN	200005
#define MAXP	400005
#define INF	1e9
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int a[MAXN], home[MAXN];
struct Segment_Tree {
	bool reversed[MAXP];
	int disable[MAXP];
	int ma[MAXP], mb[MAXP];
	int lc[MAXP], rc[MAXP];
	int root, size, n;
	void pushdown(int root) {
		if (!reversed[root]) return;
		reversed[lc[root]] ^= true;
		swap(ma[lc[root]], mb[lc[root]]);
		reversed[rc[root]] ^= true;
		swap(ma[rc[root]], mb[rc[root]]);
		reversed[root] = false;
	}
	void update(int root) {
		ma[root] = min(ma[lc[root]], ma[rc[root]]);
		mb[root] = min(mb[lc[root]], mb[rc[root]]);
		disable[root] = disable[lc[root]] + disable[rc[root]];
	}
	void build(int root, int l, int r) {
		if (l == r) {
			if (l & 1) ma[root] = a[l], mb[root] = INF;
			else mb[root] = a[l], ma[root] = INF;
			disable[root] = 0;
			return;
		}
		int mid = (l + r) / 2;
		lc[root] = ++size;
		build(lc[root], l, mid);
		rc[root] = ++size;
		build(rc[root], mid + 1, r);
		update(root);
	}
	void build(int x) {
		n = x;
		root = size = 0;
		build(root, 1, n);
	}
	int querya() {
		return ma[root];
	}
	void modify(int root, int l, int r, int pos) {
		if (l == r) {
			ma[root] = mb[root] = INF;
			disable[root] = 1;
			return;
		}
		pushdown(root);
		int mid = (l + r) / 2;
		if (mid >= pos) modify(lc[root], l, mid, pos);
		else modify(rc[root], mid + 1, r, pos);
		update(root);
	}
	void modify(int pos) {
		modify(root, 1, n, pos);
	}
	void reverse(int root, int l, int r, int ql, int qr) {
		if (l == ql && r == qr) {
			reversed[root] ^= true;
			swap(ma[root], mb[root]);
			return;
		}
		pushdown(root);
		int mid = (l + r) / 2;
		if (mid >= ql) reverse(lc[root], l, mid, ql, min(mid, qr));
		if (mid + 1 <= qr) reverse(rc[root], mid + 1, r, max(mid + 1, ql), qr);
		update(root);
	}
	void reverse(int l, int r) {
		reverse(root, 1, n, l, r);
	}
	int querys(int root, int l, int r, int ql, int qr) {
		if (l == ql && r == qr) return disable[root];
		pushdown(root);
		int mid = (l + r) / 2, ans = 0;
		if (mid >= ql) ans += querys(lc[root], l, mid, ql, min(mid, qr));
		if (mid + 1 <= qr) ans += querys(rc[root], mid + 1, r, max(mid + 1, ql), qr);
		return ans;
	}
	int queryb(int root, int l, int r, int sum) {
		if (sum == 0 && disable[root] == 0) return mb[root];
		if (l == r) return INF;
		pushdown(root);
		int mid = (l + r) / 2, ans = INF;
		if (sum <= disable[lc[root]]) ans = min(ans, queryb(lc[root], l, mid, sum));
		if (sum >= disable[lc[root]]) ans = min(ans, queryb(rc[root], mid + 1, r, sum - disable[lc[root]]));
		return ans;
	}
	int queryb(int pos) {
		int tmp = querys(root, 1, n, 1, pos);
		return queryb(root, 1, n, tmp);
	}
} ST;
int main() {
	int n; read(n);
	for (int i = 1; i <= n; i++)
		read(a[i]), home[a[i]] = i;
	ST.build(n);
	for (int i = 1; i <= n / 2; i++) {
		int ta = ST.querya();
		ST.modify(home[ta]);
		int tb = ST.queryb(home[ta]);
		printf("%d %d ", ta, tb);
		ST.modify(home[tb]);
		ST.reverse(home[ta], home[tb]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 11264