#include <bits/stdc++.h>
using namespace std;
map<long long, long long> pos;
bool compareVecs(vector<int> lhs, vector<int> rhs) {
  return pos[lhs[0]] < pos[rhs[0]];
}
int main() {
  std::ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<long long> xs(n);
  vector<long long> prev(n);
  for (long long i = 0; i < n; i++) {
    cin >> xs[i];
    pos[xs[i]] = i;
  }
  set<long long> heads;
  for (long long i = 0; i < n; i++) {
    long long val = xs[i];
    set<long long>::iterator best = heads.lower_bound(val);
    if (best == heads.begin()) {
      heads.insert(xs[i]);
      prev[i] = -1;
    } else {
      prev[i] = pos[*(--best)];
      heads.erase(best);
      heads.insert(xs[i]);
    }
  }
  vector<vector<int> > seqs;
  for (set<long long>::iterator it = heads.begin(); it != heads.end(); it++) {
    int _pos = pos[*it];
    vector<int> seq;
    while (_pos != -1) {
      seq.push_back(xs[_pos]);
      _pos = prev[_pos];
    }
    vector<int> qes;
    while (!seq.empty()) {
      qes.push_back(seq.back());
      seq.pop_back();
    }
    seqs.push_back(qes);
  }
  sort(seqs.begin(), seqs.end(), compareVecs);
  for (int i = 0; i < seqs.size(); i++) {
    for (int j = 0; j < seqs[i].size(); j++) {
      cout << seqs[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
