#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>> v;
  for (int i = 0; i < n; i++) {
    int p = a[i];
    int f = 0;
    int la = v.size();
    while (f < la) {
      int mid = f + (la - f) / 2;
      if (v[mid].back() < p) {
        la = mid;
      } else {
        f = mid + 1;
      }
    }
    if (v.size() == f)
      v.push_back({p});
    else
      v[la].push_back(p);
  }
  for (vector<int> i : v) {
    for (int j : i) {
      cout << j << " ";
    }
    cout << "\n";
  }
}
