#include <bits/stdc++.h>
using namespace std;
int ara[200005], mx_ara[200005];
queue<int> q[200005];
int main() {
  int n, i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &ara[i]);
  }
  for (i = 1; i <= n; i++) {
    int up = upper_bound(mx_ara + 1, mx_ara + i + 1, ara[i], greater<int>()) -
             mx_ara;
    q[up].push(ara[i]);
    mx_ara[up] = ara[i];
  }
  for (i = 1; i <= n; i++) {
    if (!q[i].size()) continue;
    while (!q[i].empty()) {
      int u = q[i].front();
      q[i].pop();
      printf("%d ", u);
    }
    printf("\n");
  }
}
