#include <bits/stdc++.h>
using namespace std;
vector<long> v[200000];
int n, i, j, k, l, r, m;
long a;
int main() {
  cin >> n;
  cin >> a;
  v[0].push_back(a);
  k = 0;
  for (i = 1; i < n; i++) {
    cin >> a;
    if (v[0][v[0].size() - 1] < a) {
      v[0].push_back(a);
      ;
    } else {
      r = k;
      l = 0;
      while (r != l) {
        m = (r + l) / 2;
        if (v[m][v[m].size() - 1] < a)
          r = m;
        else
          l = m + 1;
      }
      m = (r + l) / 2;
      if ((l == k) && (v[m][v[m].size() - 1] >= a)) {
        k++;
        v[k].push_back(a);
      } else
        v[l].push_back(a);
    }
  }
  for (i = 0; i <= k; i++) {
    for (j = 0; j < v[i].size(); j++) cout << v[i][j] << " ";
    cout << "\n";
  }
}
