#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > vs;
struct vectorcomp {
  bool operator()(const int& l, const int& r) {
    return vs[l][vs[l].size() - 1] < vs[r][vs[r].size() - 1];
  }
};
void printv(const vector<int>& v) {
  for (int i = 0; i < v.size(); i++) {
    if (i != 0) {
      printf(" ");
    }
    printf("%d", v[i]);
  }
  printf("\n");
}
int main() {
  int N;
  cin >> N;
  vector<int> p;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    p.push_back(a);
  }
  set<int, vectorcomp> s;
  for (int i : p) {
    vs.push_back(vector<int>(1, i));
    auto it = s.lower_bound(vs.size() - 1);
    if (s.size() == 0 || it == s.begin()) {
      s.insert(vs.size() - 1);
      continue;
    }
    it--;
    vs[*it].push_back(i);
    int tmp = *it;
    s.erase(it);
    s.insert(tmp);
  }
  for (auto i = s.rbegin(); i != s.rend(); i++) {
    printv(vs[*i]);
  }
  return 0;
}
