#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  vector<int> arr(N);
  for (auto &a : arr) cin >> a;
  vector<vector<int>> sol;
  vector<int> highests;
  vector<int> temp = {arr[0]};
  sol.push_back(temp);
  highests.push_back(arr[0]);
  for (int i = 1; i < N; ++i) {
    if (arr[i] < highests[highests.size() - 1]) {
      vector<int> t;
      t.push_back(arr[i]);
      sol.push_back(t);
      highests.push_back(arr[i]);
    } else {
      int lo = 0;
      int hi = sol.size();
      int index = -1;
      while (lo <= hi) {
        int mid = lo + (hi - lo) / 2;
        if (highests[mid] < arr[i]) {
          index = mid;
          hi = mid - 1;
        } else
          lo = mid + 1;
      }
      sol[index].push_back(arr[i]);
      highests[index] = arr[i];
    }
  }
  for (vector<int> t : sol) {
    for (int a : t) {
      cout << a << " ";
    }
    cout << endl;
  }
}
