#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits<int>::max();
const long long LLINF = numeric_limits<long long>::max();
const unsigned long long ULLINF = numeric_limits<unsigned long long>::max();
const double PI = acos(-1.0);
int ans[200010];
vector<int> val;
int a[200010];
int upper(int v) {
  int r = val.size() - 1;
  int l = 0;
  int res = -1;
  while (l <= r) {
    int m = (l + r) >> 1;
    if (val[m] < v)
      r = m - 1, res = m;
    else
      l = m + 1;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  val.push_back(a[0]);
  ans[0] = 0;
  vector<vector<int>> out;
  out.push_back(vector<int>());
  for (int i = 1; i < n; i++) {
    int v = upper(a[i]);
    if (v == -1)
      ans[i] = val.size(), val.push_back(a[i]), out.push_back(vector<int>());
    else
      ans[i] = v, val[v] = a[i];
  }
  for (int i = 0; i < n; i++) out[ans[i]].push_back(a[i]);
  for (auto k : out) {
    for (auto l : k) cout << l << " ";
    cout << '\n';
  }
  return 0;
}
