#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

struct Node {
  Node *left, *right;
  int a, b;
  int minv[2];
  bool flag;
  void pushup() {
    for (int k = 0; k < 2; ++k) {
      minv[k] = min(left->minv[k], right->minv[k]);
    }
  }
  void update() {
    flag = !flag;
    swap(minv[0], minv[1]);
  }
  void pushdown() {
    if (!flag) return;
    left->update();
    right->update();
    flag = false;
  }
};

const int N = 2e5 + 10;
int p[N], r[N], ret[N];
Node pool[N << 1], *last;
int c[N];
int n;

void add(int x) {
  for (; x <= n; x += x & -x) {
    c[x]++;
  }
}

int query(int x) {
  int ret = 0;
  for (; x; x -= x & -x) {
    ret += c[x];
  }
  return ret;
}

Node* build(int a, int b) {
  Node* cur = last++;
  cur->a = a;
  cur->b = b;
  if (a + 1 == b) {
    cur->minv[0] = cur->minv[1] = INF;
    cur->minv[a % 2] = p[a];
    cur->flag = false;
    return cur;
  }
  cur->left = build(a, (a + b) / 2);
  cur->right = build((a + b) / 2, b);
  cur->pushup();
  return cur;
}

int A, B;
int query(Node* cur, int k) {
  // trace("query", cur->a, cur->b, k);
  if (cur->a >= A && cur->b <= B) {
    return cur->minv[k];
  }
  cur->pushdown();
  int ret = INF;
  if ((cur->a + cur->b) / 2 > A) ret = min(ret, query(cur->left, k));
  if ((cur->a + cur->b) / 2 < B) ret = min(ret, query(cur->right, k));
  return ret;
}

void erase(Node* cur) {
  if (cur->a + 1 == cur->b) {
    cur->minv[0] = cur->minv[1] = INF;
    add(cur->a + 1);
    return;
  }
  cur->pushdown();
  if ((cur->a + cur->b) / 2 > A) erase(cur->left);
  else erase(cur->right);
  cur->pushup();
}

void reverse(Node* cur) {
  if (cur->a >= A && cur->b <= B) {
    cur->update();
    return;
  }
  cur->pushdown();
  if ((cur->a + cur->b) / 2 > A) reverse(cur->left);
  if ((cur->a + cur->b) / 2 < B) reverse(cur->right);
  cur->pushup();
}

int main() {
  scanf("%d", &n);
  // n = 10;
  // for (int i = 0; i < n; ++i) p[i] = i + 1;
  // random_shuffle(p, p + n);
  // for (int i = 0; i < n; ++i) printf("%d ", p[i]); puts("");
  for (int i = 0; i < n; ++i) {
    scanf("%d", &p[i]);
    r[p[i]] = i;
  }
  last = pool;
  Node* root = build(0, n);
  for (int i = 0; i < n; i += 2) {
    // trace(i);
    A = 0, B = n;
    int x = query(root, 0);
    A = r[x] + 1;
    int low = A, high = n;
    while (low != high) {
      int mid = (low + high) / 2;
      if (query(mid + 1) - query(A + 1)) {
        high = mid;
      } else {
        low = mid + 1;
      }
    }
    B = high;
    // trace(A, B);
    int y = query(root, 1);
    // trace(x, y);
    A = r[x] + 1, B = r[y];
    if (A != B) reverse(root);
    A = r[x];
    erase(root);
    A = r[y];
    erase(root);
    ret[i] = x;
    ret[i + 1] = y;
  }
  for (int i = 0; i < n; ++i) {
    printf("%d%c", ret[i], " \n"[i + 1 == n]);
  }
  return 0;
}


Measured memory_bytes: 20352