#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; map mp; rep(i, n) mp[a[i]] = i; set st; rep(i, n) st.insert(i); vector ans; while (!mp.empty()) { auto [val, idx] = *mp.begin(); auto nxt = st.upper_bound(idx); if (nxt == st.end()) { mp.erase(val); continue; } ans.push_back(val); ans.push_back(a[*nxt]); mp.erase(a[*nxt]); st.erase(*nxt); mp.erase(val); st.erase(idx); } for (int x : ans) cout << x << ' '; cout << '\n'; return 0; }