#include <bits/stdc++.h>
using namespace std;
struct aa {
  int num, x;
} a[200005];
int n, cnt = 1, Max[200005];
bool cmp(const aa &a, const aa &b) {
  if (a.num == b.num)
    return a.x < b.x;
  else
    return a.num < b.num;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i].x);
  for (int i = 1; i <= n; i++) {
    if (a[i].x < Max[cnt]) {
      Max[++cnt] = a[i].x;
      a[i].num = cnt;
      continue;
    }
    for (int j = 1; j <= cnt; j++) {
      if (a[i].x > Max[j]) {
        Max[j] = a[i].x;
        a[i].num = j;
        break;
      }
    }
  }
  sort(a + 1, a + 1 + n, cmp);
  printf("%d ", a[1].x);
  for (int i = 2; i <= n; i++) {
    if (a[i].num != a[i - 1].num) printf("\n");
    printf("%d ", a[i].x);
  }
  return 0;
}
