#include <bits/stdc++.h>
using namespace std;
vector<int> a[200000];
void bin(int x, int n) {
  int l = 0, r = n;
  while (l <= r) {
    int m = (l + r) / 2;
    if (a[m].size() == 0 || a[m][a[m].size() - 1] < x)
      l = m + 1;
    else
      r = m - 1;
  }
  a[r].push_back(x);
}
int main() {
  int n, x;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    bin(x, n - 1);
  }
  for (int i = n - 1; i >= 0; i--) {
    for (auto h : a[i]) printf("%d ", h);
    printf("\n");
  }
}
