#include <bits/stdc++.h>
using namespace std;
long long int add(long long int x, long long int y) {
  x += y;
  while (x >= 1000000007) x -= 1000000007;
  while (x < 0) x += 1000000007;
  return x;
}
long long int mul(long long int x, long long int y) {
  return (x * 1ll * y) % 1000000007;
}
long long int binpow(long long int x, long long int y) {
  long long int z = 1;
  while (y) {
    if (y & 1) z = mul(z, x);
    x = mul(x, x);
    y >>= 1;
  }
  return z;
}
long long int inv(long long int x) { return binpow(x, 1000000007 - 2); }
long long int divide(long long int x, long long int y) {
  return mul(x, inv(y));
}
struct comp {
  bool operator()(pair<int, int> p1, pair<int, int> p2) {
    if ((p1.second - p1.first) != (p2.second - p2.first))
      return (p1.second - p1.first) < (p2.second - p2.first);
    return p1.first > p2.first;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    int p[n];
    for (int i = 0; i < n; i++) cin >> p[i];
    vector<int> arr[n];
    int idx = 0;
    arr[idx].push_back(p[0]);
    int flag = 1;
    for (int i = 1; i < n; i++) {
      int l = 0, h = idx;
      if (arr[idx].back() > p[i]) {
        idx++;
        flag = 1;
        arr[idx].push_back(p[i]);
        continue;
      }
      while (l < h) {
        int mid = (l + h) / 2;
        if (arr[mid].back() > p[i])
          l = mid + 1;
        else
          h = mid;
      }
      arr[h].push_back(p[i]);
      flag = 0;
    }
    for (int i = 0; i <= idx; i++) {
      for (int j = 0; j < arr[i].size(); j++) cout << arr[i][j] << " ";
      cout << "\n";
    }
  }
  return 0;
}
