#include <bits/stdc++.h>
using namespace std;
int nx[1000000];
int main() {
  int n;
  cin >> n;
  set<int, greater<int>> st;
  vector<int> beg;
  map<int, int> mp;
  {
    int t;
    cin >> t;
    st.insert(t);
    beg.push_back(t);
  }
  for (int i = 1; i < n; ++i) {
    int t;
    cin >> t;
    auto kek = st.lower_bound(t);
    if (kek == st.end()) {
      st.insert(t);
      beg.push_back(t);
    } else {
      mp[*kek] = t;
      st.erase(kek);
      st.insert(t);
    }
  }
  for (auto i : beg) {
    while (i) {
      cout << i << ' ';
      i = mp[i];
    }
    cout << endl;
  }
  return 0;
}
