#include <bits/stdc++.h>
using namespace std;
vector<int> v[200005];
int main() {
  int n, m = 0, x;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    int l = 0, r = m;
    while (l <= r) {
      int mid = l + r >> 1;
      if (v[mid].size() && v[mid][v[mid][0]] >= x)
        l = mid + 1;
      else
        r = mid - 1;
    }
    if (!v[l].size()) v[l].push_back(0);
    v[l].push_back(x);
    v[l][0]++;
    m = max(l, m);
  }
  for (int i = 0; i <= m; i++) {
    for (int j = 1; j <= v[i][0]; j++)
      printf("%d%c", v[i][j], j == v[i][0] ? '\n' : ' ');
  }
  return 0;
}
