#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[2 * maxn], b[2 * maxn];
vector<int> G[2 * maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    int pos = lower_bound(b, b + n, a[i]) - b;
    pos--;
    b[pos] = a[i];
    G[pos].push_back(a[i]);
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < G[i].size(); j++) {
      if (j == G[i].size() - 1)
        printf("%d\n", G[i][j]);
      else
        printf("%d ", G[i][j]);
    }
  }
}
