#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > mtree;
int main() {
  int i, n, v, lo, hi, mid;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &v);
    lo = 0;
    hi = mtree.size();
    while (lo != hi) {
      mid = (lo + hi) / 2;
      if (mtree[mid].back() < v)
        hi = mid;
      else
        lo = mid + 1;
    }
    if (lo == mtree.size())
      mtree.push_back(vector<int>(1, v));
    else
      mtree[lo].push_back(v);
  }
  for (auto x : mtree) {
    for (auto y : x) printf("%d ", y);
    puts("");
  }
  return 0;
}
