#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
const long long M = 1e9 + 7;
const long long M2 = 998244353;
void input() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < (long long)n; ++i) cin >> a[i];
  vector<vector<long long>> v;
  multiset<pair<long long, long long>> s;
  for (long long i = 0; i < (long long)n; ++i) {
    if (v.empty()) {
      v.push_back({a[i]});
    } else {
      long long l = 0, r = v.size();
      while (l < r) {
        long long m = (l + r) / 2;
        if (v[m].back() <= a[i]) {
          r = m;
        } else {
          l = m + 1;
        }
      }
      if (l == v.size()) {
        v.push_back({a[i]});
      } else {
        v[r].push_back(a[i]);
      }
    }
  }
  for (auto i : v) {
    for (auto j : i) {
      cout << j << " ";
    }
    cout << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  long long a = 1;
  while (t--) {
    solve();
    a += 1;
  }
}
