#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  queue<int> q[n];
  int m[n];
  memset(m, -1, sizeof(m));
  int in, p;
  for (int i = 0; i < n; i++) {
    scanf("%d", &in);
    p = upper_bound(m, m + n, in) - m - 1;
    q[p].push(in);
    m[p] = in;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (q[i].empty()) break;
    while (1) {
      printf("%d", q[i].front());
      q[i].pop();
      if (!q[i].empty()) {
        printf(" ");
      } else {
        printf("\n");
        break;
      }
    }
  }
}
