#include <bits/stdc++.h>

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;
struct Min {
  using T = pair<int, int>;
  T operator()(const T a, const T b) {
    return min(a, b);
  }
};
template <class M>
class SparseTable {
  using V = typename M::T;
  M calc;

 public:
  SparseTable() = default;
  //SparseTable &operator=(const SparseTable &) = default;
  SparseTable(vector<V> &v) : n(v.size()), lg2(n + 1) {
    for (int i = 2; i <= n; ++i) {
      lg2[i] = lg2[i >> 1] + 1;
    }
    data = vector<vector<V>>(lg2[n] + 1, vector<V>(n));
    data[0] = v;
    for (int i = 1; i < data.size(); ++i) {
      for (int j = 0; j <= n - (1 << i); ++j) {
        data[i][j] = calc(data[i - 1][j], data[i - 1][j + (1 << (i - 1))]);
      }
    }
    DBG(data)
  };

 private:
  size_t n;
  vector<size_t> lg2;
  vector<vector<V>> data;

 public:
  size_t size() { return n; }
  V query(int l, int r) {
    int len = r - l;
    int lg = lg2[len];
    return calc(data[lg][l], data[lg][r - (1 << lg)]);
  }
};
struct P {
  int a, b, p, q, l, r;
  bool operator<(const P &rhs) const {
    return a > rhs.a or (a == rhs.a and b > rhs.b);
  }
};
class Solver {
 public:
  int n;
  vector<vector<pair<int, int>>> p;
  vector<SparseTable<Min>> st;
  Solver(LL n) : n(n), p(2), st(2){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      int tmp;
      cin >> tmp;
      p[i % 2].emplace_back(tmp, i);
      p[(i + 1) % 2].emplace_back(INF, -1);
    }
    for (int i = 0; i < 2; ++i) {
      st[i] = SparseTable<Min>(p[i]);
    }
    priority_queue<P> pq;
    vector<int> ans;
    {
      auto mini = st[0].query(0, n);
      auto min2 = st[1].query((mini.second + 1), n);
      pq.push(P{mini.first, min2.first, mini.second, min2.second, 0, n});
      DBG(mini.first, min2.first, mini.second, min2.second, 0, n)
    }
    int na = 0;
    while (!pq.empty()) {
      auto now = pq.top();
      pq.pop();
      ans.push_back(now.a);
      ans.push_back(now.b);
      if (na < 20) DBG(now.l, now.r, now.p, now.q)
      na++;
      if (now.l < now.p - 1) {
        auto mini = st[now.l % 2].query(now.l, now.p);
        auto min2 = st[(now.l + 1) % 2].query((mini.second + 1), now.p);
        if (na < 20) DBG(mini.first, min2.first, mini.second, min2.second, now.l, now.p)
        pq.push(P{mini.first, min2.first, mini.second, min2.second, now.l, now.p});
      }
      if (now.p < now.q - 1) {
        auto mini = st[(now.p + 1) % 2].query((now.p + 1), now.q);
        DBG(mini)
        auto min2 = st[((now.p + 1) + 1) % 2].query((mini.second + 1), now.q);
        if (na < 20) DBG(mini.first, min2.first, mini.second, min2.second, (now.p + 1), now.q)
        pq.push(P{mini.first, min2.first, mini.second, min2.second, (now.p + 1), now.q});
      }
      if (now.q < now.r - 1) {
        auto mini = st[(now.q + 1) % 2].query((now.q + 1), now.r);
        auto min2 = st[((now.q + 1) + 1) % 2].query((mini.second + 1), now.r);
        if (na < 20) DBG(mini.first, min2.first, mini.second, min2.second, (now.q + 1), now.r)
        pq.push(P{mini.first, min2.first, mini.second, min2.second, (now.q + 1), now.r});
      }
    }
    for (int i = 0; i < (int)ans.size(); ++i) {
      cout << ans[i] << ' ';
    }
    cout << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 67400