#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  map<int, int> p;
  map<int, int> m;
  rep(i, N) {
    int pi; cin >> pi;
    p[i] = pi;
    m[pi] = i;
  }
  vector<int> q;
  int n = N;
  while ((int)q.size() < N) {
    map<int, int>::iterator it = m.begin();
    if (it->second == n - 1)
      it++;
    int x = it->second;
    map<int, int>::iterator it2 = p.find(x);
    it2++;
    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;
}