#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1];
  vector<int> g[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  set<pair<int, int> > last;
  int k = 0;
  for (int i = 1; i <= n; i++) {
    set<pair<int, int> >::iterator it = last.lower_bound(make_pair(a[i], 1));
    if (it == last.begin()) {
      g[++k].push_back(a[i]);
      last.insert(make_pair(a[i], k));
    } else {
      --it;
      g[it->second].push_back(a[i]);
      last.erase(it);
      last.insert(make_pair(a[i], it->second));
    }
  }
  for (int i = 1; i <= k; i++) {
    for (int j : g[i]) {
      cout << j << " ";
    }
    cout << endl;
  }
}
