#include <bits/stdc++.h>
using namespace std;
const int len = 2e5 + 5;
const long long mod = 998244353;
const unsigned long long seed = 131;
vector<int> ve[len];
vector<int> gg;
int main() {
  int n;
  cin >> n;
  int l = 0;
  for (int i = 1; i <= n; ++i) {
    int t;
    scanf("%d", &t);
    if (gg.size() == 0)
      gg.push_back(t), ve[l++].push_back(t);
    else {
      int p = lower_bound(gg.begin(), gg.end(), t, greater<int>()) - gg.begin();
      if (p == l)
        gg.push_back(t), ve[l++].push_back(t);
      else
        ve[p].push_back(t), gg[p] = t;
    }
  }
  for (int i = 0; i < l; ++i) {
    for (int j = 0; j < ve[i].size(); ++j) cout << ve[i][j] << ' ';
    puts("");
  }
}
