#include using namespace std; int main() { int n; cin >> n; vector p(n); vector r(n, 1); set ex; for(int i = 0; i < n; i++) { cin >> p[i]; p[i]--; ex.insert(i); r[p[i]] = i; } vector ans; for(int i = 0; i < n; i++){ if(r[i] >= 0){ auto itr = ex.upper_bound(r[i]); if(itr == ex.end()) continue; ans.emplace_back(i + 1); ans.emplace_back(p[*itr] + 1); r[p[*itr]] = -1; ex.erase(itr); ex.erase(r[i]); r[i] = -1; } } for(int i = 0; i < n; i++){ cout << ans[i] << " \n"[i == n-1]; } }