#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<int>> ans;
  int n;
  scanf("%d", &n);
  while (n--) {
    int x;
    scanf("%d", &x);
    int l = 0, r = (int)ans.size() - 1, res = -1;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (ans[mid].back() < x) {
        res = mid;
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    if (res == -1) {
      ans.push_back({x});
    } else {
      ans[res].push_back(x);
    }
  }
  for (auto &y : ans) {
    for (int x : y) printf("%d ", x);
    puts("");
  }
}
