#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 10;
int A[N];
int B[N];
vector<int> V[N];
int main() {
  int x, y;
  cin >> x;
  vector<int>::iterator it;
  for (int i = 1; i <= x; ++i) {
    cin >> y;
    int z = lower_bound(B, B + x, y, greater<int>()) - B;
    V[z].push_back(y);
    B[z] = y;
  }
  for (int i = 0; V[i].size() > 0; ++i) {
    it = V[i].begin();
    cout << *it;
    ++it;
    while (it != V[i].end()) {
      cout << " " << *it;
      ++it;
    }
    cout << endl;
  }
}
