#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
const int MAX_N = 2e5;
vector<bool> head(MAX_N);
int nxt[MAX_N];
struct node {
  long long x, idx;
  node(long long _x, int _idx) : x(_x), idx(_idx) {}
  bool operator<(const node& b) const { return x > b.x; }
};
int main() {
  int N;
  cin >> N;
  vector<long long> nums(N);
  for (auto& x : nums) cin >> x;
  set<node> s;
  for (int i = 0; i < N; i++) {
    auto it = s.lower_bound(node(nums[i], 0));
    if (it == s.end()) {
      head[i] = true;
      s.insert(node(nums[i], i));
    } else {
      nxt[it->idx] = i;
      s.erase(it);
      s.insert(node(nums[i], i));
    }
  }
  for (int i = 0; i < N; i++) {
    if (head[i]) {
      cout << nums[i] << ' ';
      long long nt = nxt[i];
      while (nt != 0) {
        cout << nums[nt] << ' ';
        nt = nxt[nt];
      }
      cout << '\n';
    }
  }
  return 0;
}
