#include <bits/stdc++.h>
using std::vector;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  size_t n;
  std::cin >> n;
  vector<size_t> data(n);
  for (auto& elem : data) {
    std::cin >> elem;
  }
  vector<vector<size_t>> ans;
  for (size_t i = 0; i < n; ++i) {
    int left = 0, right = ans.size() - 1;
    while (left <= right) {
      int mid = (left + right) / 2;
      if (ans[mid].back() > data[i]) {
        left = mid + 1;
      } else {
        right = mid - 1;
      }
    }
    if (ans.size() <= left) {
      ans.push_back(vector<size_t>());
    }
    ans[left].push_back(data[i]);
  }
  for (auto vec : ans) {
    for (auto elem : vec) {
      std::cout << elem << ' ';
    }
    std::cout << '\n';
  }
  return 0;
}
