#include <bits/stdc++.h>
using namespace std;
int n, x;
vector<int> a[200001];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    int l = 1, r = n;
    while (l <= r) {
      int m = (l + r) / 2;
      if (a[m].size() == 0 || a[m][a[m].size() - 1] < x)
        l = m + 1;
      else
        r = m - 1;
    }
    a[r].push_back(x);
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 0; j < a[i].size(); j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
