#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  ;
  int n;
  cin >> n;
  vector<vector<int> > ans;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    int low = 0, high = ans.size() - 1;
    int it = -1;
    while (low <= high) {
      int mid = (low + high) / 2;
      if (ans[mid].size()) {
        if (x > ans[mid][ans[mid].size() - 1]) {
          it = mid;
          high = mid - 1;
        } else {
          low = mid + 1;
        }
      }
    }
    if (it == -1) {
      vector<int> blank;
      blank.push_back(x);
      ans.push_back(blank);
    } else {
      ans[it].push_back(x);
    }
  }
  for (vector<int> v : ans) {
    for (int x : v) {
      cout << x << " ";
    }
    cout << "\n";
  }
  return 0;
}
