#include <bits/stdc++.h>
using namespace std;
vector<long long> V[200005];
long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w,
    x, y, z, pre;
long long A[200005];
string S, T, st;
void bnc(long long a) {
  long long lo, hi, mid;
  lo = 1;
  hi = l;
  while (lo <= hi) {
    mid = (lo + hi + 1) / 2;
    if (A[mid - 1] > a && A[mid] < a) {
      V[mid].push_back(a);
      A[mid] = a;
      return;
    }
    if (A[mid] < a)
      hi = mid;
    else
      lo = mid;
  }
  return;
}
int main() {
  cin >> n >> a;
  V[1].push_back(a);
  A[0] = 100000000000000000;
  A[1] = a;
  l = 1;
  for (i = 0; i < n - 1; i++) {
    cin >> a;
    if (a < A[l]) {
      l++;
      V[l].push_back(a);
      A[l] = a;
    } else if (a > A[1]) {
      A[1] = a;
      V[1].push_back(a);
    } else
      bnc(a);
  }
  for (i = 1; i <= l; i++) {
    for (j = 0; j < V[i].size(); j++) {
      cout << V[i][j] << ' ';
    }
    cout << endl;
  }
  return 0;
}
