#include <bits/stdc++.h>
using namespace std;
int mi[201000 << 2], n, a[201000];
void build(int l, int r, int rt) {
  if (l == r) {
    mi[rt] = a[l];
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  mi[rt] = max(mi[rt << 1], mi[rt << 1 | 1]);
}
void update(int pos, int l, int r, int rt) {
  if (l == r) {
    mi[rt] = -1;
    return;
  }
  int m = (l + r) >> 1;
  if (pos <= m)
    update(pos, l, m, rt << 1);
  else
    update(pos, m + 1, r, rt << 1 | 1);
  mi[rt] = max(mi[rt << 1], mi[rt << 1 | 1]);
}
int Q(int pos, int l, int r, int rt) {
  if (l == r) return mi[rt];
  int m = (l + r) >> 1;
  if (pos <= m)
    return Q(pos, l, m, rt << 1);
  else
    return Q(pos, m + 1, r, rt << 1 | 1);
}
int query(int val, int L, int R, int l, int r, int rt) {
  if (l == r) {
    if (mi[rt] > val) {
      return l;
    }
    return -1;
  }
  if (l >= L && r <= R && mi[rt] <= val) return -1;
  int m = (l + r) >> 1, ans = -1;
  if (L <= m && mi[rt << 1] > val) ans = query(val, L, R, l, m, rt << 1);
  if (ans == -1 && R > m && mi[rt << 1 | 1] > val)
    ans = query(val, L, R, m + 1, r, rt << 1 | 1);
  return ans;
}
bool vis[201000];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  build(1, n, 1);
  int pos = 0, cur;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    vis[i] = true;
    cout << a[i] << ' ';
    cur = i;
    pos = 0;
    while (pos != -1 && cur != n) {
      pos = query(a[cur], cur + 1, n, 1, n, 1);
      if (pos == -1) break;
      vis[pos] = true;
      update(pos, 1, n, 1);
      cur = pos;
      cout << a[pos] << ' ';
    }
    cout << endl;
  }
  return 0;
}
