#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-9;
const long long mod = 1e9 + 7;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch<'0' | ch> '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void Out(int aa) {
  if (aa > 9) Out(aa / 10);
  putchar(aa % 10 + '0');
}
int a[200010];
int b[200010];
vector<int> vec[200010];
int main() {
  int n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  priority_queue<pair<int, int> > q2;
  int cnt = 0;
  vec[cnt].push_back(a[1]);
  b[cnt++] = -a[1];
  for (int i = 2; i <= n; i++) {
    int pos = lower_bound(b, b + cnt, -a[i]) - b;
    if (pos == cnt) {
      vec[cnt].push_back(a[i]);
      b[cnt++] = -a[i];
    } else {
      vec[pos].push_back(a[i]);
      b[pos] = -a[i];
    }
  }
  for (int i = 0; i < cnt; i++) {
    for (int j = 0; j < vec[i].size(); j++) {
      printf("%d ", vec[i][j]);
    }
    printf("\n");
  }
  return 0;
}
