#include <bits/stdc++.h>
using namespace std;
deque<long long int> top[200010];
long long int a[200010];
int len, n;
int Lower_update(int len, int x) {
  int low = 0, high = len;
  while (low < high) {
    int mid = (low + high) / 2;
    if (*top[mid].rbegin() <= x) {
      high = mid;
    } else {
      low = mid + 1;
    }
  }
  if (high == len) {
    return -1;
  }
  return high;
}
void solve() {
  for (int i = 0; i < n; i++) {
    int res = Lower_update(len, a[i]);
    if (res == -1) {
      top[len++].push_back(a[i]);
    } else {
      top[res].push_back(a[i]);
    }
  }
  for (int i = 0; i < len; i++) {
    cout << top[i].front();
    top[i].pop_front();
    while (!top[i].empty()) {
      cout << " " << top[i].front();
      top[i].pop_front();
    }
    cout << endl;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  len = 0;
  solve();
  return 0;
}
