#include <bits/stdc++.h>
using namespace std;
map<long long, int> ValToInt;
set<long long> Set;
vector<long long> ans[200010];
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n, next = 0;
  long long aux;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> aux;
    set<long long>::iterator it = Set.upper_bound(-aux);
    if (it == Set.end()) {
      next++;
      ValToInt[-aux] = next;
      ans[next].push_back(aux);
      Set.insert(-aux);
    } else {
      long long valTemporal = *it;
      Set.erase(valTemporal);
      int ind = ValToInt[valTemporal];
      ValToInt[-aux] = ind;
      ans[ind].push_back(aux);
      Set.insert(-aux);
    }
  }
  for (int i = 1; i <= next; i++) {
    cout << ans[i][0];
    for (int j = 1; j < ans[i].size(); j++) {
      cout << " " << ans[i][j];
    }
    cout << "\n";
  }
}
