#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<list<int>> seq(n, list<int>(1, 0));
  while (n--) {
    int x;
    cin >> x;
    int lo = 0, hi = seq.size() - 1;
    while (lo < hi) {
      int mid = (lo + hi) / 2;
      if (seq[mid].back() < x)
        hi = mid;
      else
        lo = mid + 1;
    }
    seq[lo].push_back(x);
  }
  for (auto& s : seq) {
    s.pop_front();
    if (s.empty()) continue;
    for (int x : s) cout << x << ' ';
    cout << '\n';
  }
  return 0;
}
