#include <bits/stdc++.h>
using namespace std;
const double eps = 0.0000000001;
const int MOD = 1e9 + 7;
const int MAXN = 2 * 1e5 + 5;
vector<int> t;
vector<int> ans[MAXN];
int serch(int a, int b, int c) {
  if (c > t[a]) return (a);
  if (c < t[b - 1]) return (b);
  if (b - a <= 1)
    return (a);
  else {
    int m = (b + a) / 2;
    if (c > t[m])
      return (serch(a, m, c));
    else
      return (serch(m, b, c));
  }
}
int main() {
  int n;
  cin >> n;
  int x;
  cin >> x;
  t.push_back(x);
  ans[0].push_back(x);
  for (int i = 1; i < n; i++) {
    cin >> x;
    int j = serch(0, t.size(), x);
    if (j == t.size()) {
      ans[t.size()].push_back(x);
      t.push_back(x);
    } else {
      ans[j].push_back(x);
      t[j] = x;
    }
  }
  for (int i = 0; i < t.size(); i++) {
    for (int j = 0; j < ans[i].size(); j++) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
  return (0);
}
