#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, tmp;
  cin >> n;
  vector<queue<int> > lst;
  vector<int> sp;
  while (n--) {
    cin >> tmp;
    bool b = true;
    vector<int>::reverse_iterator I = lower_bound(sp.rbegin(), sp.rend(), tmp);
    if (I == sp.rbegin()) {
      queue<int> hj;
      hj.push(tmp);
      lst.push_back(hj);
      sp.push_back(tmp);
    } else {
      I--;
      *I = tmp;
      (lst.rbegin() + (I - sp.rbegin()))->push(tmp);
    }
  }
  for (vector<queue<int> >::iterator i = lst.begin(); i != lst.end(); i++) {
    int z = i->size();
    while (z--) {
      cout << i->front() << " ";
      i->pop();
    }
    cout << "\n";
  }
  return 0;
}
