#include <bits/stdc++.h>
using namespace std;
const int oo = (1 << 30);
const int MAX = 2 * 1e5 + 7;
vector<int> ady[MAX];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> data(n);
  for (int i = 0; i < n; i++) cin >> data[i];
  deque<int> aux;
  aux.push_back(data[0]);
  for (int i = 0; i < n; i++) {
    int act = data[i];
    auto p = upper_bound(aux.begin(), aux.end(), act);
    if (p == aux.end()) {
      ady[aux.size() - (p - aux.begin())].push_back(act);
      aux[p - aux.begin() - 1] = act;
    } else {
      if (p == aux.begin()) {
        aux.push_front(act);
        ady[aux.size() - 1].push_back(act);
      } else {
        ady[aux.size() - (p - aux.begin())].push_back(act);
        aux[p - aux.begin() - 1] = act;
      }
    }
  }
  for (int i = 0; i < aux.size(); i++) {
    for (int j = 0; j < ady[i].size(); j++) {
      if (j > 0) cout << " ";
      cout << ady[i][j];
    }
    cout << '\n';
  }
  return 0;
}
