#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
int a[200200], n;
int t[200200 * 4];
void build(int v, int l, int r) {
  if (l == r) {
    t[v] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(v + v, l, mid), build(v + v + 1, mid + 1, r);
  t[v] = max(t[v + v], t[v + v + 1]);
}
void update(int v, int l, int r, int pos, int val) {
  if (l == r) {
    t[v] = val;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(v + v, l, mid, pos, val);
  else
    update(v + v + 1, mid + 1, r, pos, val);
  t[v] = max(t[v + v], t[v + v + 1]);
}
int getmax(int v, int l, int r, int L, int R) {
  if (r < L || R < l) return -inf;
  if (L <= l && r <= R) return t[v];
  int mid = (l + r) >> 1;
  return max(getmax(v + v, l, mid, L, R), getmax(v + v + 1, mid + 1, r, L, R));
}
int get(int l, int r, int val) {
  if (l > r) return -1;
  if (l == r) {
    if (a[l] > val)
      return l;
    else
      return -1;
  }
  int mid = (l + r) >> 1;
  int res1 = getmax(1, 1, n, l, mid);
  int res2 = getmax(1, 1, n, mid + 1, r);
  if (res1 > val)
    return get(l, mid, val);
  else
    return get(mid + 1, r, val);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  build(1, 1, n);
  vector<int> cur;
  for (int i = 1, j = 1; i <= n; ++i) {
    cur.push_back(a[j]);
    update(1, 1, n, j, -inf);
    int nx = get(j + 1, n, a[j]);
    a[j] = -inf;
    if (nx == -1) {
      for (int k = 0; k < cur.size(); ++k) {
        cout << cur[k] << " ";
      }
      cout << "\n";
      cur.clear();
      j = get(1, n, -inf);
    } else {
      j = nx;
    }
  }
  return 0;
}
