#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; map::iterator it2 = p.find(x); it2++; int y = it2->first; q.push_back(p[x]); q.push_back(p[y]); m.erase(p[x]); m.erase(p[y]); p.erase(x); p.erase(y); } rep(i, N) cout << q[i] << " "; cout << endl; return 0; }