#include <bits/stdc++.h>
using namespace std;
template <class T>
T min(T a, T b, T c) {
  return min(a, min(b, c));
}
template <class T>
T min(T a, T b, T c, T d) {
  return min(a, min(b, min(c, d)));
}
template <class T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
template <class T>
T max(T a, T b, T c, T d) {
  return max(a, max(b, max(c, d)));
}
bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
  return (a.first > b.first || (a.first == b.first && a.second >= b.second));
}
long long GCD(long long a, long long b) { return (a % b) ? GCD(b, a % b) : b; }
const string namePro = "tmp";
vector<int> vc[200007];
int a[200007], pos[200007];
int main() {
  int n;
  scanf("%d", &n);
  set<pair<int, int> > st;
  for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]);
  for (int i = (1); i <= (n); ++i) {
    set<pair<int, int> >::iterator it = st.lower_bound(make_pair(-a[i], 0));
    if (it == st.end()) {
      st.insert(make_pair(-a[i], i));
      pos[i] = i;
      vc[pos[i]].push_back(i);
    } else {
      pos[i] = (*it).second;
      st.erase(it);
      st.insert(make_pair(-a[i], pos[i]));
      vc[pos[i]].push_back(i);
    }
  }
  for (int i = (1); i <= (n); ++i) {
    for (int j = (0); j <= ((int)vc[i].size() - 1); ++j)
      printf("%d ", a[vc[i][j]]);
    if (vc[i].size()) puts("");
  }
  return 0;
}
