#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > A;
vector<int> vec;
int pos(int xcur) {
  int pb = 0, pe = A.size(), md;
  while (pe > pb + 1) {
    md = (pe + pb) >> 1;
    if (A[md].back() > xcur)
      pb = md;
    else
      pe = md;
  }
  return pb;
}
int main() {
  int n;
  cin >> n;
  vec.resize(n);
  for (int i = 0; i < n; i++) cin >> vec[i];
  A.push_back({vec[0]});
  for (int i = 1; i < n; i++) {
    int cur = vec[i];
    int xpos = pos(cur);
    if (A[xpos].back() < cur)
      A[xpos].push_back(cur);
    else {
      if (xpos + 1 == A.size()) A.push_back({});
      A[xpos + 1].push_back(cur);
    }
  }
  for (int i = 0; i < A.size(); i++) {
    for (int j = 0; j < A[i].size(); j++) cout << A[i][j] << " ";
    cout << "\n";
  }
  return 0;
}
