#include <bits/stdc++.h>
using namespace std;
vector<int> vc[2 * 100005];
const int inf = 2000000007;
int ara[2 * 100005];
int main() {
  int n;
  while (cin >> n) {
    vector<int> vc[n + 5];
    for (int i = 1; i <= n; i++) {
      cin >> ara[i];
      vc[i].push_back(0);
    }
    for (int i = 1; i <= n; i++) {
      int idx = 0;
      int low = 1, high = n;
      while (low <= high) {
        int mid = (low + high) / 2;
        if (vc[mid].back() < ara[i]) {
          high = mid - 1;
          idx = mid;
        } else
          low = mid + 1;
      }
      vc[idx].push_back(ara[i]);
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j < vc[i].size(); j++) {
        cout << vc[i][j] << ' ';
      }
      if (vc[i].size() != 1) cout << endl;
    }
  }
  return 0;
}
