#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn];
vector<int> v[maxn];
int main() {
  int n;
  int cnt = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    int pos = lower_bound(a + 1, a + 1 + n, x) - a;
    pos--;
    a[pos] = x;
    v[pos].push_back(x);
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 0; j < v[i].size(); j++) printf("%d ", v[i][j]);
    cout << endl;
  }
}
