#include <bits/stdc++.h>
using namespace std;
int a[200005];
int nxt[200005];
bool head[200005];
struct Node {
  int idx, val;
  bool operator<(const Node &other) const { return val > other.val; }
};
int main(void) {
  set<Node> s;
  memset(nxt, -1, sizeof(nxt));
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", a + i);
  for (int i = 0; i < N; i++) {
    auto it = s.upper_bound({i, a[i]});
    if (it == s.end()) {
      head[i] = true;
      s.insert({i, a[i]});
    } else {
      nxt[it->idx] = i;
      s.erase(it);
      s.insert({i, a[i]});
    }
  }
  for (int i = 0; i < N; i++) {
    if (head[i] == false) continue;
    int j = i;
    while (j != -1) {
      printf("%d ", a[j]);
      j = nxt[j];
    }
    printf("\n");
  }
}
