#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> ans(1);
void bin(int l, int r, int num) {
  if (num < ans.back().back()) {
    vector<int> tmp(1, num);
    ans.push_back(tmp);
    return;
  }
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (ans[mid].back() < num)
      r = mid;
    else
      l = mid;
  }
  if (ans[l].back() < num)
    ans[l].push_back(num);
  else
    ans[r].push_back(num);
}
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  ans[0].push_back(v[0]);
  for (int i = 1; i < n; ++i) {
    bin(0, ans.size() - 1, v[i]);
  }
  for (int i = 0; i < ans.size(); ++i) {
    for (int j = 0; j < ans[i].size(); ++j) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
