#include <bits/stdc++.h>
using namespace std;
const long long mxn = 2e5 + 10;
vector<long long> a[mxn];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long m = 0;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    long long l = 0, r = m;
    while (l < r) {
      long long mid = (l + r) / 2;
      if (a[mid].back() < x)
        r = mid;
      else
        l = mid + 1;
    }
    a[l].push_back(x);
    m = max(m, l + 1);
  }
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < (long long)a[i].size(); j++) {
      cout << a[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
