#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, ai;
  int idx = 0;
  scanf("%ld", &n);
  vector<long> arr;
  deque<long> aux;
  vector<vector<long>> ans;
  for (int i = 0; i < n; i++) {
    scanf("%ld", &ai);
    arr.push_back(ai);
  }
  aux.push_back(arr[0]);
  ans.push_back({arr[0]});
  for (int i = 1; i < n; i++) {
    idx = lower_bound(aux.begin(), aux.end(), arr[i]) - aux.begin();
    if (idx == 0) {
      aux.push_front(arr[i]);
      ans.push_back({arr[i]});
    } else {
      aux[idx - 1] = arr[i];
      ans[aux.size() - idx].push_back(arr[i]);
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    for (int j = 0; j < ans[i].size(); j++) std::cout << ans[i][j] << " ";
    std::cout << '\n';
  }
}
