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