#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 2e5 + 4;
int tree[4 * N], a[N];
void build(int node, int st, int end) {
  if (st == end) {
    tree[node] = a[st];
    return;
  }
  int mid = (st + end) / 2;
  build(2 * node, st, mid);
  build(2 * node + 1, mid + 1, end);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
void update(int node, int st, int end, int ind, int val) {
  if (st == end) {
    tree[node] = val;
    return;
  }
  int mid = (st + end) / 2;
  if (ind <= mid)
    update(2 * node, st, mid, ind, val);
  else
    update(2 * node + 1, mid + 1, end, ind, val);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
int query(int node, int st, int end, int l, int r) {
  if (st > r or end < l) return 0;
  if (st >= l and end <= r) return tree[node];
  int mid = (st + end) / 2;
  return max(query(2 * node, st, mid, l, r),
             query(2 * node + 1, mid + 1, end, l, r));
}
int main() {
  int n;
  scanf("%d", &n);
  set<int> ist;
  set<pair<int, int>> st;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  build(1, 0, n - 1);
  vector<int> mark(n, 0);
  int cur = 0;
  while (1) {
    while (cur < n and mark[cur]) cur++;
    if (cur == n) break;
    vector<int> v;
    int tcur = cur;
    while (1) {
      v.push_back(a[tcur]);
      mark[tcur] = 1;
      update(1, 0, n - 1, tcur, 0);
      int low = tcur + 1, high = n - 1, ans = -1;
      while (low <= high) {
        int mid = (low + high) / 2;
        if (query(1, 0, n - 1, tcur + 1, mid) > a[tcur])
          ans = mid, high = mid - 1;
        else
          low = mid + 1;
      }
      if (ans == -1) break;
      tcur = ans;
    }
    for (int it : v) printf("%d ", it);
    printf("\n");
  }
  return 0;
}
