#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  vector<int> ends;
  vector<vector<int>> ans;
  for (int i = 0; i < n; i++) {
    bool found = false;
    if (!ends.empty() && a[i] > ends.back()) {
      for (int j = 0; j < ends.size(); j++) {
        if (a[i] > ends[j]) {
          found = true;
          ans[j].push_back(a[i]);
          ends[j] = a[i];
          break;
        }
      }
    }
    if (!found) {
      ans.push_back(vector<int>());
      ans.back().push_back(a[i]);
      ends.push_back(a[i]);
    }
  }
  for (auto b : ans) {
    for (auto d : b) printf("%d ", d);
    printf("\n");
  }
  return 0;
}
