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