#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
vector<int> V[N], U;
int find_(int x) {
  if (U.size() == 0) return -1;
  int l = 0, r = U.size() - 1, mid;
  while (l < r) {
    mid = l + r >> 1;
    if (U[mid] > x)
      l = mid + 1;
    else
      r = mid;
  }
  if (U[l] > x)
    return -1;
  else
    return l;
}
int main() {
  int n, x, p, idx = 0;
  scanf("%d", &n);
  memset(V, 0, sizeof V);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    p = find_(x);
    if (p == -1) {
      V[idx++].push_back(x);
      U.insert(U.end(), x);
    } else {
      U[p] = x;
      V[p].push_back(x);
    }
  }
  for (int i = 0; i < idx; i++) {
    for (int j = 0; j < V[i].size(); j++) {
      printf("%d ", V[i][j]);
    }
    printf("\n");
  }
  return 0;
}
