#include <bits/stdc++.h>
using namespace std;
vector<int> a[300000];
int n;
int cnt = 0;
void bp(int t) {
  int l = 0;
  int r = cnt;
  int c;
  while (r - l > 1) {
    c = (l + r) / 2;
    if (a[c][a[c].size() - 1] < t) {
      r = c;
    } else {
      l = c;
    }
  }
  if (a[l][a[l].size() - 1] > t) {
    l++;
  }
  a[l].push_back(t);
  if (l == cnt) cnt++;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tmp;
  cin >> n >> tmp;
  a[cnt++].push_back(tmp);
  for (int i = 1; i < n; i++) {
    cin >> tmp;
    bp(tmp);
  }
  for (int i = 0; i < cnt; i++) {
    for (int j = 0; j < a[i].size(); j++) {
      cout << a[i][j] << ' ';
    }
    cout << '\n';
  }
  return 0;
}
