#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<ll, ll> pll;

const int DEPTH = 18;
const int NUM_ELEMS = 1 << DEPTH;

pii evenragetree[2 * NUM_ELEMS];
pii oddragetree[2 * NUM_ELEMS];

inline pii getEven(int idx) {
  return evenragetree[idx];
}
inline pii getOdd(int idx) {
  return oddragetree[idx];
}

void build(int idx) {
  assert(idx >= NUM_ELEMS);
  idx /= 2;
  while(idx) {
    evenragetree[idx] = min(getEven(2*idx), getEven(2*idx+1));
    oddragetree[idx] = min(getOdd(2*idx), getOdd(2*idx+1));
    idx /= 2;
  }
}

pii minEven(int l, int r) {
  pii ret = {1e9, -1};
  l += NUM_ELEMS;
  r += NUM_ELEMS;
  while(l <= r) {
    if(l == r) {
      ret = min(ret, evenragetree[l]);
      break;
    }
    if(l%2) {
      ret = min(ret, evenragetree[l]);
      l++;
    }
    if(r%2 == 0) {
      ret = min(ret, evenragetree[r]);
      r--;
    }
    l /= 2;
    r /= 2;
  }
  return ret;
}

pii minOdd(int l, int r) {
  pii ret = {1e9, -1};
  l += NUM_ELEMS;
  r += NUM_ELEMS;
  while(l <= r) {
    if(l == r) {
      ret = min(ret, oddragetree[l]);
      break;
    }
    if(l%2) {
      ret = min(ret, oddragetree[l]);
      l++;
    }
    if(r%2 == 0) {
      ret = min(ret, oddragetree[r]);
      r--;
    }
    l /= 2;
    r /= 2;
  }
  return ret;
}

int getPriority(pii p) {
  pii ff;
  if(p.first%2) {
    ff = minOdd(p.first, p.second);
  }
  else {
    ff = minEven(p.first, p.second);
  }
  return -ff.first;
}

void upd(int idx, int val) {
  if(idx % 2) oddragetree[idx + NUM_ELEMS] = {val, idx};
  else evenragetree[idx + NUM_ELEMS] = {val, idx};
  idx += NUM_ELEMS;
  build(idx);
}

int n;

void solve() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    oddragetree[i+NUM_ELEMS] = {1e9, 1e9};
    evenragetree[i+NUM_ELEMS] = {1e9, 1e9};
  }
  for(int i = 0; i < n; i++) {
    int t;
    cin >> t;
    upd(i, t);
  }
  vector<pii> ret;
  priority_queue<pipii> q;
  q.push({getPriority({0, n-1}), {0, n-1}});
  while(!q.empty()) {
    pipii curr = q.top();
    q.pop();
    pii ff, ss;
    if(curr.second.first%2) {
      ff = minOdd(curr.second.first, curr.second.second);
      ss = minEven(ff.second+1, curr.second.second);
    }
    else {
      ff = minEven(curr.second.first, curr.second.second);
      ss = minOdd(ff.second+1, curr.second.second);
    }
    ret.push_back({ff.first, ss.first});
    if(ff.second > curr.second.first) q.push({getPriority({curr.second.first, ff.second-1}), {curr.second.first, ff.second-1}});
    if(ff.second+1 < ss.second) q.push({getPriority({ff.second+1, ss.second-1}), {ff.second+1, ss.second-1}});
    if(ss.second < curr.second.second) q.push({getPriority({ss.second+1, curr.second.second}), {ss.second+1, curr.second.second}});
  }
  for(auto out: ret) cout << out.first << " " << out.second << " "; cout << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 10764