#include <bits/stdc++.h>
std::vector<std::vector<int> > GetSolution(const std::vector<int> &array,
                                           const int n) {
  std::vector<std::vector<int> > solution;
  std::set<std::pair<int, int> > iterations;
  for (auto x : array) {
    auto it = iterations.lower_bound({-x, -1});
    if (it == iterations.end()) {
      std::vector<int> v = {x};
      solution.push_back(v);
      iterations.emplace(-x, (int)solution.size() - 1);
    } else {
      int list_index = it->second;
      solution[list_index].emplace_back(x);
      iterations.erase(it);
      iterations.emplace(-x, list_index);
    }
  }
  return solution;
}
int main() {
  int n;
  scanf("%d", &n);
  std::vector<int> array(n);
  for (auto &i : array) {
    scanf("%d", &i);
  }
  std::vector<std::vector<int> > solution = GetSolution(array, n);
  for (std::vector<int> &v : solution) {
    for (int &i : v) {
      printf("%d ", i);
    }
    printf("\n");
  }
  return 0;
}
