#include <bits/stdc++.h>
using namespace std;
long long int a[200005];
vector<long long int> v[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, i, j, k, l, m, res1, res2;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  v[0].push_back(a[1]);
  long long int lastpoint = 0;
  for (i = 2; i <= n; i++) {
    if (v[lastpoint].back() > a[i]) {
      lastpoint++;
      v[lastpoint].push_back(a[i]);
    } else {
      long long int ini = 0;
      long long int fina = lastpoint;
      long long int p = 32;
      long long int mid;
      while (fina - ini >= 5) {
        mid = (ini + fina) / 2;
        if (v[mid].back() < a[i])
          fina = mid;
        else
          ini = mid;
      }
      int flag = -1;
      for (j = ini; j <= fina; j++) {
        if (v[j].back() < a[i]) {
          flag = j;
          break;
        }
      }
      if (flag == -1)
        v[lastpoint].push_back(a[i]);
      else {
        v[j].push_back(a[i]);
      }
    }
  }
  for (i = 0; i <= lastpoint; i++) {
    long long int sz = v[i].size();
    for (j = 0; j < sz; j++) cout << v[i][j] << " ";
    cout << endl;
  }
  return 0;
}
