#include using namespace std; //#include //using namespace atcoder; using ll = long long int; using ull = unsigned long long int; using ld = long double; constexpr ll MAX = 2000000000000000000; constexpr ld PI = 3.14159265358979; constexpr ll MOD = 0;//2024948111; ld dotorad(ld K){ return PI * K / 180.0; } ld radtodo(ld K){ return K * 180.0 / PI; } mt19937 mt; void randinit(){ srand((unsigned)time(NULL));mt = mt19937(rand()); } int main(){ ll N; cin >> N; set> st; vector A(N),doko(N + 1),ans; for(ll i = 0; i < N; i++){ cin >> A[i]; doko[A[i]] = i; st.insert({i,A[i]}); } for(ll i = 1;i <= N;i++){ auto p = st.lower_bound({doko[i],i}); if(p == st.end()) continue; if(*p != make_tuple(doko[i],i)) continue; auto q = p; q++; if(q == st.end()) continue; ll x = i,y = get<1>(*q); st.erase(p); st.erase(q); ans.emplace_back(x); ans.emplace_back(y); } for(ll i = 0;i < (ll)ans.size();i++){ cout << ans[i] << " \n"[i == (ll)ans.size() - 1]; } }