#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int inf = 1234567890;
struct node {
  int val, Ti;
  bool operator<(const node& T) const { return val < T.val; }
} k[maxn];
int tree[maxn << 2], a[maxn], bel[maxn];
vector<int> rcd[maxn];
void Buildtree(int l, int r, int key) {
  if (l == r) {
    tree[key] = k[l].Ti;
    return;
  }
  int mid = (l + r) >> 1;
  Buildtree(l, mid, key << 1);
  Buildtree(mid + 1, r, key << 1 | 1);
  tree[key] = min(tree[key << 1], tree[key << 1 | 1]);
}
void Update(int ls, int rs, int pos, int val, int key) {
  if (ls == rs) {
    tree[key] = val;
    return;
  }
  int mid = (ls + rs) >> 1;
  if (pos <= mid)
    Update(ls, mid, pos, val, key << 1);
  else
    Update(mid + 1, rs, pos, val, key << 1 | 1);
  tree[key] = min(tree[key << 1], tree[key << 1 | 1]);
}
int Query(int ls, int rs, int l, int r, int key) {
  if (l <= ls && rs <= r) return tree[key];
  int mid = (ls + rs) >> 1, ans = inf;
  if (l <= mid) ans = min(ans, Query(ls, mid, l, r, key << 1));
  if (mid < r) ans = min(ans, Query(mid + 1, rs, l, r, key << 1 | 1));
  return ans;
}
int Find_pos(int l, int r, int key) {
  int mid = (l + r) >> 1;
  if (k[mid].val == key)
    return mid;
  else if (key < k[mid].val)
    return Find_pos(l, mid - 1, key);
  else
    return Find_pos(mid + 1, r, key);
}
void Deal(int pos, int s, int n) {
  int ovo;
  while (!bel[pos]) {
    bel[pos] = s;
    rcd[s].push_back(a[pos]);
    ovo = Find_pos(1, n, a[pos]);
    Update(1, n, ovo, inf, 1);
    if (ovo != n) {
      int want = Query(1, n, ovo + 1, n, 1);
      if (want != inf) pos = want;
    }
  }
}
int main() {
  int n, num = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    k[i].val = a[i];
    k[i].Ti = i;
  }
  sort(k + 1, k + n + 1);
  Buildtree(1, n, 1);
  for (int i = 1; i <= n; i++) {
    if (bel[i]) continue;
    Deal(i, ++num, n);
  }
  for (int i = 1; i <= num; i++) {
    for (int j = 0, s = rcd[i].size(); j < s; j++) {
      printf("%d%c", rcd[i][j], j == s - 1 ? '\n' : ' ');
    }
  }
  return 0;
}
