#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

struct M {
  using T = pair<int, int>;
  using U = int;
  static T op(const T& a, const T& b) { return T(min(a.first, b.first), max(a.second, b.second)); }
  static constexpr T e() { return T(numeric_limits<int>::max(), numeric_limits<int>::min()); }
  static void ap(T& a, const U& g, int k) { a.first *= g, a.second *= g; if (g < 0) swap(a.first, a.second); }
  static void ap(U& f, const U& g) { f *= g; }
  static constexpr U id() { return 1; }
};

template<class M> struct ST {
  using T = typename M::T;
  using U = typename M::U;
  int n;
  V<T> t;
  V<U> u;
  V<> k;

  ST(int n) : n(n) {
    t.assign(2 * n, M::e());
    u.assign(n, M::id());
    k.assign(2 * n, 1);
    for (int i = n - 1; i; i--) k[i] = k[2 * i] + k[2 * i + 1];
  }

  void _ap(int i, const U& f) {
    M::ap(t[i], f, k[i]);
    if (i < n) M::ap(u[i], f);
  }

  void build() {
    for (int i = n - 1; i; i--) t[i] = M::op(t[2 * i], t[2 * i + 1]);
  }

  T get(int l, int r) {
    _push(l, r);
    T resl = M::e(), resr = M::e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = M::op(resl, t[l++]);
      if (r & 1) resr = M::op(t[--r], resr);
    }
    return M::op(resl, resr);
  }

  void push() {
    for (int i = 1; i < n; i++) {
      _ap(2 * i, u[i]);
      _ap(2 * i + 1, u[i]);
      u[i] = M::id();
    }
  }

  void _push(int l, int r) {
    for (int hl = 8 * sizeof(int) - __builtin_clz(l + n) - 1, hr = 8 * sizeof(int) - __builtin_clz(r - 1 + n) - 1; hr > 0; hl--, hr--) {
      int i = r - 1 + n >> hr;
      _ap(2 * i, u[i]);
      _ap(2 * i + 1, u[i]);
      u[i] = M::id();
      i = l + n >> hl;
      if (i == r - 1 + n >> hr or i >= n) continue;
      _ap(2 * i, u[i]);
      _ap(2 * i + 1, u[i]);
      u[i] = M::id();
    }
  }

  void set(int l, int r, const U& f) {
    _push(l, r);
    for (int i = l + n, j = r + n; i < j; i >>= 1, j >>= 1) {
      if (i & 1) _ap(i++, f);
      if (j & 1) _ap(--j, f);
    }
    for (l += n; !(l & 1);) l >>= 1;
    while (l >>= 1) t[l] = M::op(t[2 * l], t[2 * l + 1]);
    for (r += n; !(r & 1);) r >>= 1;
    while (r >>= 1) t[r] = M::op(t[2 * r], t[2 * r + 1]);
  }
};

struct M2 {
  using T = int;
  static T op(const T& a, const T& b) { return a + b; }
  static constexpr T e() { return 0; }
};

template<class M> struct ST2 {
  using T = typename M::T;
  int n;
  V<T> t;

  ST2(int n) : n(n) {
    t.assign(2 * n, M::e());
  }

  void build() {
    for (int i = n - 1; i; i--) t[i] = M::op(t[2 * i], t[2 * i + 1]);
  }

  T get(int l, int r) {
    T resl = M::e(), resr = M::e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) { 
      if (l & 1) resl = M::op(resl, t[l++]); 
      if (r & 1) resr = M::op(t[--r], resr);
    }
    return M::op(resl, resr);
  }

  void set(int i, const T& a) {
    for (t[i += n] = a; i >>= 1;) t[i] = M::op(t[2 * i], t[2 * i + 1]);
  }
};

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> p(n); for (int i = 0; i < n; i++) cin >> p[i], p[i] = n + 1 - p[i];
  V<> ip(n + 1); for (int i = 0; i < n; i++) ip[p[i]] = i;
  ST<M> st(n);
  for (int i = 0; i < n; i++) st.t[i + n].first = st.t[i + n].second = (i & 1 ? -p[i] : p[i]);
  st.build();
  ST2<M2> st2(n);
  V<> q;
  for (int i = 0; i < n / 2; i++) {
    int em = st.get(0, n).second;
    q.push_back(em);
    st.set(ip[em], ip[em] + 1, 0);
    st2.set(ip[em], 1);

    int l = ip[em], r = n;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (st2.get(ip[em], m + 1) > 1) r = m;
      else l = m;
    }

    int om = st.get(ip[em], l + 1).first * -1;
    q.push_back(om);
    st.set(ip[om], ip[om] + 1, 0);
    st2.set(ip[om], 1);

    st.set(ip[em], ip[om] + 1, -1);
  }
  for (int i = 0; i < n; i++) cout << n + 1 - q[i] << (i != n - 1 ? ' ' : '\n');
}


Measured memory_bytes: 11000