#include <bits/stdc++.h>
int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
using namespace std;
long long power(long long a, long long p, long long M) {
  long long r = 1;
  a = a % M;
  while (p > 0) {
    if (p % 2) r = (r * a) % M;
    a = (a * a) % M;
    p /= 2;
  }
  return r;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int n;
long long a[200000];
vector<long long> v[200000];
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  ;
  for (int i = 0; i < n; i++) {
    v[i].push_back(0);
  }
  for (int i = 0; i < n; i++) {
    long long l = 0, r = n - 1;
    while (l <= r) {
      long long mid = (l + r) / 2;
      if (v[mid][v[mid].size() - 1] < a[i]) {
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    v[l].push_back(a[i]);
  }
  for (int i = 0; i < n; i++) {
    if (v[i].size() > 1) {
      for (int j = 1; j < v[i].size(); j++) {
        printf("%lld ", v[i][j]);
      }
      printf("\n");
    } else {
      break;
    }
  }
}
int main() {
  solve();
  return 0;
}
