#include <bits/stdc++.h>
using namespace std;
inline void out(int a) { printf("%d\n", a); }
inline void out(int a, int b) { printf("%d %d\n", a, b); }
inline void outf(double a) { printf("%3.lf\n", a); }
inline void outf(double a, double b) { printf("%3.lf %3.lf\n", a, b); }
inline void base() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
vector<int> ans[200005];
int main() {
  base();
  int n;
  cin >> n;
  vector<int> lds;
  int a;
  cin >> a;
  lds.push_back(a);
  ans[0].push_back(a);
  n--;
  while (n--) {
    cin >> a;
    int l = 0, r = lds.size();
    while (l < r) {
      int m = (l + r) / 2;
      if (lds[m] >= a)
        l = m + 1;
      else
        r = m;
    }
    if (l == lds.size())
      lds.push_back(a), ans[l].push_back(a);
    else
      lds[l] = a, ans[l].push_back(a);
  }
  for (int(i) = 0; (i) < (lds.size()); (i)++) {
    for (int(j) = 0; (j) < (ans[i].size()); (j)++) {
      if (j) cout << " ";
      cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}
