#include <bits/stdc++.h>
using namespace std;
int search(int b[], int low, int high, int val) {
  int mid;
  mid = (low + high + 1) / 2;
  if (b[mid] < val && b[mid - 1] > val)
    return mid;
  else if (b[mid] < val)
    return search(b, mid - 1, high, val);
  else
    return search(b, low, mid, val);
}
int main() {
  int n, i, j, index1 = 1, index2;
  scanf("%d", &n);
  int a[n], b[n];
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  vector<int> v[n];
  v[0].push_back(a[0]);
  b[0] = a[0];
  for (i = 1; i < n; i++) {
    if (a[i] < b[index1 - 1]) {
      v[index1].push_back(a[i]);
      b[index1] = a[i];
      index1++;
    } else if (a[i] > b[0]) {
      v[0].push_back(a[i]);
      b[0] = a[i];
    } else {
      index2 = search(b, index1 - 1, 0, a[i]);
      v[index2].push_back(a[i]);
      b[index2] = a[i];
    }
  }
  for (i = 0; i < n; i++) {
    if (v[i].size() == 0) break;
    for (j = 0; j < v[i].size(); j++) printf("%d ", v[i][j]);
    printf("\n");
  }
  return 0;
}
