#include <bits/stdc++.h>
const long long int INF = 1e9 + 12312, MOD = 1e9, MAXN = 200000;
const long double EPS = 0.000001;
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n), d(n + 55);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> g[300005];
  int l = 0, r = n + 1;
  for (int i = 0; i < n; i++) {
    int ch = a[i];
    l = -1, r = n + 1;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (d[m] >= ch) {
        l = m;
      } else
        r = m;
    }
    d[r] = ch;
    g[r].push_back(ch);
  }
  for (int i = 0; i < n; i++) {
    if (d[i] != 0) {
      for (auto j : g[i]) cout << j << " ";
    }
    cout << "\n";
  }
  return 0;
}
