#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e12;
vector<long long> ans[200010];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) ans[i].push_back(-1);
  ans[0][0] = a[0];
  long long sz = 1;
  for (long long i = 1; i < n; i++) {
    long long l = -1, r = sz;
    while (r - l > 1) {
      long long mid = (l + r) / 2;
      long long tmp = ans[mid][ans[mid].size() - 1];
      if (tmp > a[i]) {
        l = mid;
      } else {
        r = mid;
      }
    }
    if (r == sz) {
      ans[r][0] = a[i];
      sz++;
    } else {
      ans[r].push_back(a[i]);
    }
  }
  for (long long i = 0; i < sz; i++) {
    for (long long ii = 0; ii < ans[i].size(); ii++) {
      if (ii) cout << ' ';
      cout << ans[i][ii];
    }
    cout << endl;
  }
}
