#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long cl(long double a) {
  if (a > (long long)a) {
    return (long long)a + 1;
  } else {
    return (long long)a;
  }
}
long long flr(long double a) {
  if (a < 0.0) {
    return (long long)a - 1;
  }
  return (long long)a;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long pw(long long n, long long k) {
  if (k == 0) return 1;
  long long t = pw(n, k / 2);
  long long ans = (t * t) % mod;
  if (k % 2)
    return (ans * n) % mod;
  else
    return ans;
}
const long long M = 2e5 + 100;
vector<long long> res[M];
vector<long long> op;
long long bs(long long num) {
  if (num < op.back()) return -1;
  long long ans, s = 0, e = op.size() - 1;
  while (s <= e) {
    long long mid = (s + e) / 2;
    if (op[mid] < num) {
      ans = mid;
      e = mid - 1;
    } else {
      s = mid + 1;
    }
  }
  return ans;
}
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) {
    if (op.empty()) {
      res[(long long)op.size()].push_back(a[i]);
      op.push_back(a[i]);
    } else {
      long long idx = bs(a[i]);
      if (idx == -1) {
        res[(long long)op.size()].push_back(a[i]);
        op.push_back(a[i]);
      } else {
        res[idx].push_back(a[i]);
        op[idx] = a[i];
      }
    }
  }
  long long i = 0;
  while (res[i].size() > 0) {
    for (auto x : res[i]) cout << x << " ";
    i++;
    cout << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) solve();
}
