#include <bits/stdc++.h>
using namespace std;
inline void boostIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int N = 200200, oo = 1e9;
int n, i, a[N], idx[N], seg[N * 4];
bool vis[N];
vector<vector<int>> ans;
map<int, int> mp;
int build(int id = 1, int l = 0, int r = n) {
  if (l == r - 1) return seg[id] = idx[l];
  int lChild = id * 2;
  int rChild = id * 2 + 1;
  int mid = (l + r) / 2;
  return seg[id] = min(build(lChild, l, mid), build(rChild, mid, r));
}
int update(int x, int y, int v, int id = 1, int l = 0, int r = n) {
  if (x >= r || y <= l) return seg[id];
  if (x <= l && y >= r) {
    return seg[id] = v;
  }
  int lChild = id * 2;
  int rChild = id * 2 + 1;
  int mid = (l + r) / 2;
  return seg[id] = min(update(x, y, v, lChild, l, mid),
                       update(x, y, v, rChild, mid, r));
}
int getMin(int x, int y, int id = 1, int l = 0, int r = n) {
  if (x >= r || y <= l) return oo;
  if (x <= l && y >= r) return seg[id];
  int lChild = id * 2;
  int rChild = id * 2 + 1;
  int mid = (l + r) / 2;
  return min(getMin(x, y, lChild, l, mid), getMin(x, y, rChild, mid, r));
}
vector<int> fill(int k) {
  vector<int> res;
  res.push_back(a[k]);
  vis[k] = 1;
  int l = mp[a[k]];
  update(l, l + 1, oo);
  while ((k = getMin(mp[a[k]] + 1, n + 1)) < oo) {
    vis[k] = 1;
    res.push_back(a[k]);
    l = mp[a[k]];
    update(l, l + 1, oo);
  }
  return res;
}
int main() {
  boostIO();
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> a[i];
    mp[a[i]];
  }
  i = 0;
  for (auto& it : mp) {
    it.second = i++;
  }
  for (i = 0; i < n; ++i) {
    idx[mp[a[i]]] = i;
  }
  build();
  for (i = 0; i < n; ++i) {
    if (vis[i]) {
      continue;
    }
    ans.push_back(fill(i));
  }
  for (auto& vec : ans) {
    for (int x : vec) {
      cout << x << ' ';
    }
    cout << endl;
  }
  return 0;
}
