#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const long long LINF = INF * 1ll * INF;
const double PI = acos(-1.0);
using namespace std;
int a[200005];
vector<int> ans[200005];
int biSearch(int val, int sz) {
  int l = 0, r = sz;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (ans[mid].back() <= val)
      r = mid;
    else
      l = mid + 1;
  }
  if (r == sz) return -1;
  return r;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (cnt == 0) {
      ans[cnt++].push_back(a[i]);
      continue;
    }
    int p = biSearch(a[i], cnt);
    if (p == -1)
      ans[cnt++].push_back(a[i]);
    else
      ans[p].push_back(a[i]);
  }
  for (int i = 0; i < cnt; i++) {
    for (int j = 0; j < ans[i].size(); j++) {
      if (j == 0)
        printf("%d", ans[i][j]);
      else
        printf(" %d", ans[i][j]);
    }
    puts("");
  }
  return 0;
}
