#include <bits/stdc++.h>
using namespace std;
const int N = (int)(2e5 + 123);
map<int, int> pmx;
vector<int> ans[N];
int a[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int cnt = 1;
  for (int i = 1; i <= n; i++) {
    auto it = pmx.lower_bound(a[i]);
    if (it != pmx.begin()) {
      it--;
      int x = (*it).second;
      pmx[a[i]] = x;
      pmx.erase((*it).first);
      ans[x].push_back(a[i]);
    } else {
      pmx[a[i]] = cnt;
      ans[cnt].push_back(a[i]);
      cnt++;
    }
  }
  for (int i = 1; i <= cnt; i++) {
    for (int j = 0; j < ans[i].size(); j++) cout << ans[i][j] << " ";
    cout << endl;
  }
}
