#include <bits/stdc++.h>
using namespace std;
const int MAXN = int(1e5) + 10;
const int MOD = int(1e9) + 7;
const int oo = INT_MAX;
int n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  while (cin >> n) {
    vector<vector<int> > v;
    for (int i = 0; i < n; ++i) {
      int x;
      cin >> x;
      int lo = 0, hi = int((v).size()) - 1;
      while (lo <= hi) {
        int mi = (lo + hi) >> 1;
        if (v[mi].back() > x) {
          lo = mi + 1;
        } else {
          hi = mi - 1;
        }
      }
      if (lo == int((v).size())) {
        v.push_back({x});
      } else {
        v[lo].push_back(x);
      }
    }
    for (int i = 0; i < int((v).size()); ++i) {
      for (auto& e : v[i]) {
        cout << e << ' ';
      }
      cout << '\n';
    }
  }
  return 0;
}
