#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<long long int, int> process;
  vector<long long int> temp;
  int group_num = 1;
  vector<vector<long long int> > output(n + 1);
  for (int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    int index = lower_bound(temp.begin(), temp.end(), -a) - temp.begin();
    if (index == temp.size()) {
      temp.push_back(-a);
      process[a] = group_num++;
    } else {
      process[a] = process[-temp[index]];
      temp[index] = -a;
    }
    output[process[a]].push_back(a);
  }
  for (int i = 1; i < group_num; i++) {
    for (int j = 0; j < output[i].size(); j++) cout << output[i][j] << " ";
    cout << '\n';
  }
}
