#include #include #include #include int main() { using namespace std; int n; cin >> n; map m; set> s; vector ans; for (int p, i = 0; i < n; ++i) cin >> p, s.emplace(i, p), m[p] = i; for (int j = 1; j <= n; ++j) { auto it = s.lower_bound({m.at(j) + 1, 0}); if (it == s.end()) continue; ans.push_back(j); s.erase({m.at(j), j}); auto [_, u] = *it; ans.push_back(u); m.at(u) = n; s.erase(it); } for (bool first = true; const auto& i : ans) { if (first) first = false; else cout << ' '; cout << i; } cout << '\n'; }