#include <bits/stdc++.h>
using namespace std;
int n;
int f[222222];
vector<int> res[222222 * 2];
int main() {
  scanf("%d", &n);
  int l = 222222;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    int p = lower_bound(f + l, f + 222222, x) - f - 1;
    f[p] = x;
    if (p < l) l = p;
    res[p].push_back(x);
  }
  for (int i = 222222; i >= l; i--)
    if ((int)res[i].size()) {
      for (int j = 0; j < (int)res[i].size(); j++)
        printf("%d%c", res[i][j], (j < (int)res[i].size() - 1) ? ' ' : '\n');
    }
  return 0;
}
