#include <bits/stdc++.h>
using namespace std;
const int maxi = 211111;
int a[maxi];
vector<int> v[maxi];
void print(int x) {
  for (int i = 0; i < v[x].size(); i++) {
    printf("%d", v[x][i]);
    if (i == v[x].size() - 1)
      puts("");
    else
      printf(" ");
  }
}
int main() {
  int n;
  int num = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    int cur = a[i];
    int lo = 0, hi = num;
    while (lo != hi) {
      int mid = (lo + hi) / 2;
      int t;
      if (v[mid].size() == 0)
        t = 0;
      else
        t = v[mid].back();
      if (t < cur)
        hi = mid;
      else
        lo = mid + 1;
    }
    if (v[lo].size() == 0) num++;
    v[lo].push_back(cur);
  }
  for (int i = 0; i <= num; i++) print(i);
  return 0;
}
