#include <bits/stdc++.h>
using namespace std;
int t[4 * 200005];
int a[200005], b[200005], C = 0, N;
void update(int node, int lo, int hi, int in, int val) {
  if (lo == hi) {
    t[node] = val;
    return;
  }
  int md = (lo + hi) >> 1;
  if (in <= b[md])
    update(node << 1, lo, md, in, val);
  else
    update(node << 1 | 1, md + 1, hi, in, val);
  t[node] = min(t[node << 1], t[node << 1 | 1]);
}
int query(int node, int lo, int hi, int l, int r) {
  if (b[lo] > r or b[hi] < l) return N + 1;
  if (b[lo] >= l and b[hi] <= r) return t[node];
  int md = (lo + hi) >> 1;
  return min(query(node << 1, lo, md, l, r),
             query(node << 1 | 1, md + 1, hi, l, r));
}
vector<int> v[200005];
int main() {
  int i, j;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + N);
  for (i = 0; i < 4 * 200005; i++) t[i] = N + 1;
  update(1, 0, N - 1, a[0], 0);
  v[0].push_back(a[0]);
  for (i = 1; i < N; i++) {
    int j = query(1, 0, N - 1, 0, a[i]);
    if (j == N + 1) {
      v[++C].push_back(a[i]);
      update(1, 0, N - 1, a[i], C);
    } else {
      int last = v[j][v[j].size() - 1];
      v[j].push_back(a[i]);
      update(1, 0, N - 1, last, N + 1);
      update(1, 0, N - 1, a[i], j);
    }
  }
  for (i = 0; i <= C; i++) {
    for (j = 0; j < v[i].size(); j++) cout << v[i][j] << " ";
    cout << endl;
  }
  return 0;
}
