#include <bits/stdc++.h>
using namespace std;
vector<int> a[int(2e5 + 5)];
int m[int(2e5 + 5)];
int main() {
  int n, x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    int id = lower_bound(m, m + int(2e+5), x, greater<int>()) - m;
    a[id].push_back(x);
    m[id] = x;
  }
  for (int i = 0; !a[i].empty(); i++) {
    for (auto t : a[i]) cout << t << " ";
    cout << endl;
  }
  return 0;
}
