#include <bits/stdc++.h>
using namespace std;
map<int, int> val;
int a[200007];
vector<int> res[200005];
int id = 0;
int main() {
  iostream::sync_with_stdio();
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < (int)(n); ++i) {
    auto it = val.upper_bound(-a[i]);
    if (it != val.end()) {
      res[it->second].push_back(a[i]);
      val[-a[i]] = it->second;
      val.erase(it);
    } else {
      res[id].push_back(a[i]);
      val[-a[i]] = id++;
    }
  }
  for (auto it = val.begin(); it != val.end(); ++it) {
    for (int i = 0; i < (int)(res[it->second].size()); ++i) {
      cout << res[it->second][i] << " ";
    }
    cout << "\n";
  }
}
