#include <bits/stdc++.h>
using namespace std;
int main() {
  int size;
  cin >> size;
  vector<vector<int>> vv;
  int tmp;
  cin >> tmp;
  vv.push_back(vector<int>{tmp});
  for (int i = 1; i < size; i++) {
    cin >> tmp;
    bool inserted = false;
    auto it = lower_bound(vv.begin(), vv.end(), tmp,
                          [](const vector<int>& to_ins, const int& t) {
                            return to_ins.back() > t;
                          });
    if (it != vv.end()) {
      it->push_back(tmp);
    } else {
      vv.push_back(vector<int>{tmp});
    }
  }
  for (int i = 0; i < vv.size(); i++) {
    for (int j = 0; j < vv[i].size(); j++) {
      cout << vv[i][j] << " ";
    }
    cout << endl;
  }
}
