#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
vector<int> res[maxn];
vector<int> num(maxn, 0);
int n;
int myLowerBound(int a) {
  int l = 0, r = n;
  while (l < r) {
    int mid = l + (r - l) / 2;
    if (num[mid] <= a)
      r = mid;
    else if (num[mid] > a)
      l = mid + 1;
  }
  return l;
}
int main() {
  int maxx = 0;
  scanf("%d", &n);
  int a;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    int pos = myLowerBound(a);
    num[pos] = a;
    res[pos].push_back(a);
    maxx = max(pos, maxx);
  }
  getchar();
  for (int i = 0; i <= maxx; i++) {
    for (int j = 0; j < res[i].size(); j++) {
      printf("%d ", res[i][j]);
    }
    printf("\n");
  }
  return 0;
}
