#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int N; cin >> N; map p; map m; rep(i, N) { int pi; cin >> pi; p[i] = pi; m[pi] = i; } vector q; int n = N; while ((int)q.size() < N) { map::iterator it = m.begin(); if (it->second == n - 1) it++; int x = it->second; int y = x + 1; while (m.find(p[y]) == m.end()) y++; q.push_back(p[x]); q.push_back(p[y]); m.erase(p[x]); m.erase(p[y]); } rep(i, N) cout << q[i] << " "; cout << endl; return 0; }