#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long MOD = 1e9 + 7;
double EPS = 1e-8;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> v(n);
  for (int i = (0); i < (int)(n); i++) {
    scanf("%d", &v[i]);
  }
  vector<vector<int>> ans;
  map<int, int> mp;
  for (int i = (0); i < (int)(n); i++) {
    if (mp.empty()) {
      ans.push_back(vector<int>());
      ans.back().push_back(v[i]);
      mp[v[i]] = 0;
    } else {
      auto it = mp.upper_bound(v[i]);
      if (it == mp.begin()) {
        ans.push_back(vector<int>());
        ans.back().push_back(v[i]);
        mp[v[i]] = ans.size() - 1;
      } else {
        --it;
        int k = it->second;
        ans[k].push_back(v[i]);
        mp[v[i]] = k;
        mp.erase(it);
      }
    }
  }
  for (int i = (0); i < (int)(ans.size()); i++) {
    for (int j = (0); j < (int)(ans[i].size()); j++) {
      if (j != 0) printf(" ");
      printf("%d", ans[i][j]);
    }
    printf("\n");
  }
  return 0;
}
