#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
long long a[MAXN];
int n;
vector<long long> g[MAXN];
int lst[MAXN];
int tot;
int solve(long long ai) {
  int l = -1, r = tot;
  while (l + 1 < r) {
    int mid = (l + r) >> 1;
    if (lst[mid] < ai)
      r = mid;
    else
      l = mid;
  }
  return r;
}
int main() {
  while (cin >> n) {
    for (int i = 1; i <= n; ++i) cin >> a[i];
    memset(lst, 0, sizeof lst);
    for (int i = 1; i <= n; ++i) {
      if (tot == 0 || a[i] <= lst[tot - 1]) {
        lst[tot] = a[i];
        g[tot++].push_back(a[i]);
      } else {
        int tid = solve(a[i]);
        lst[tid] = a[i];
        g[tid].push_back(a[i]);
      }
    }
    for (int i = 0; i < tot; ++i) {
      for (auto tmp : g[i]) {
        cout << tmp << " ";
      }
      cout << endl;
    }
    for (int i = 0; i <= tot; ++i) g[i].clear();
  }
  return 0;
}
