#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; while ((int)q.size() < N) { map::iterator it, it2; it = m.begin(); while (1) { it2 = p.find(it->second); it2++; if (it2 != p.end()) break; it++; } int x = it->second; 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; }