Ivan has an array consisting of n different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into one sorted array.

Ivan represent his array with increasing sequences with help of the following algorithm.

While there is at least one unused number in array Ivan repeats the following procedure:

  * iterate through array from the left to the right; 
  * Ivan only looks at unused numbers on current iteration; 
  * if current number is the first unused number on this iteration or this number is greater than previous unused number on current iteration, then Ivan marks the number as used and writes it down. 



For example, if Ivan's array looks like [1, 3, 2, 5, 4] then he will perform two iterations. On first iteration Ivan will use and write numbers [1, 3, 5], and on second one — [2, 4].

Write a program which helps Ivan and finds representation of the given array with one or several increasing sequences in accordance with algorithm described above.

Input

The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of elements in Ivan's array.

The second line contains a sequence consisting of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — Ivan's array.

Output

Print representation of the given array in the form of one or more increasing sequences in accordance with the algorithm described above. Each sequence must be printed on a new line.

Examples

Input

5
1 3 2 5 4


Output

1 3 5 
2 4 


Input

4
4 3 2 1


Output

4 
3 
2 
1 


Input

4
10 30 50 101


Output

10 30 50 101 
#include <bits/stdc++.h>
using namespace std;
int INF = 2e9;
vector<int> pref(string& s) {
  int n = s.size();
  vector<int> g(n, 0);
  for (int i = 1; i < n; i++) {
    int j = g[i - 1];
    while (j > 0 and s[i] != s[j]) {
      j = g[j - 1];
    }
    if (s[i] == s[j]) j++;
    g[i] = j;
  }
  return g;
}
int N = 3e5 + 10;
vector<long long> tree;
void build(vector<int>& g, int v, int tl, int tr) {
  if (tl == tr)
    tree[v] = g[tl];
  else {
    int tm = (tl + tr) / 2;
    build(g, 2 * v, tl, tm);
    build(g, 2 * v + 1, tm + 1, tr);
    tree[v] = max(tree[2 * v], tree[2 * v + 1]);
  }
}
int find_max(int v, int tl, int tr, int l, int r) {
  if (l > r) return 0;
  if (tl == l and tr == r) return tree[v];
  int tm = (tl + tr) / 2;
  return max(find_max(2 * v, tl, tm, l, min(tm, r)),
             find_max(2 * v + 1, tm + 1, tr, max(tm + 1, l), r));
}
void update(long long v, long long tl, long long tr, long long pos,
            long long val) {
  if (tl == tr)
    tree[v] = val;
  else {
    long long tm = (tl + tr) / 2;
    if (pos <= tm)
      update(2 * v, tl, tm, pos, val);
    else
      update(2 * v + 1, tm + 1, tr, pos, val);
    tree[v] = max(tree[2 * v], tree[2 * v + 1]);
  }
}
long long bin_pow(long long a, long long b, long long m) {
  if (b == 0) return 1;
  a %= m;
  if (b % 2 == 0) {
    return bin_pow(a * a, b / 2, m) % m;
  } else
    return (a * bin_pow(a, b - 1, m)) % m;
}
unsigned long long numbers(unsigned long long n) {
  unsigned long long a = 0;
  while (n != 0) {
    n /= 10;
    a++;
  }
  return a;
}
unsigned long long num(unsigned long long n) {
  unsigned long long t = 0;
  while (n != 0) {
    t += n % 10;
    n /= 10;
  }
  return t;
}
char f(string s) {
  if (s[0] == 'a' and s[1] == 'b' or s[1] == 'a' and s[0] == 'b') return 'c';
  if (s[0] == 'a' and s[1] == 'c' or s[1] == 'a' and s[0] == 'c') return 'b';
  if (s[0] == 'b' and s[1] == 'c' or s[1] == 'b' and s[0] == 'c') return 'a';
}
vector<int> ssize;
vector<int> parent;
int find_set(int v) {
  if (v == parent[v]) {
    return v;
  }
  return parent[v] = find_set(parent[v]);
}
void union_set(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (ssize[a] < ssize[b]) {
      parent[a] = b;
      ssize[b] += ssize[a];
    } else {
      parent[b] = a;
      ssize[a] += ssize[b];
    }
  }
}
void f(int v, int l, int r, int pos) {
  if (l == r)
    tree[v] = 1;
  else {
    int m = (l + r) / 2;
    if (m >= pos) {
      f(2 * v + 1, l, m, pos);
    } else {
      f(2 * v + 2, m + 1, r, pos);
    }
    tree[v] = tree[2 * v + 1] + tree[2 * v + 2];
  }
}
int F(int v, int l, int r, int sum) {
  if (l == r) {
    return l;
  }
  int m = (l + r) / 2;
  if (tree[2 * v + 1] < sum) {
    return F(2 * v + 2, m + 1, r, sum - tree[2 * v + 1]);
  } else {
    return F(2 * v + 1, l, m, sum);
  }
}
struct wor {
  long long a, b, c, d, e;
};
bool cmp(wor w1, wor w2) { return w1.a > w2.a; }
bool cmp1(wor w1, wor w2) { return w1.b < w2.b; }
bool cmp2(wor w1, wor w2) { return w1.c < w2.c; }
double C_n_k(int n, int k) {
  k = max(n - k, k);
  double ans = 1;
  int pow_two = n + 1;
  for (int i = k + 1; i <= n; i++) {
    ans *= i;
    while (ans > 1e5 and pow_two != 0) {
      ans /= 2;
      pow_two--;
    }
  }
  for (int i = 1; i <= n - k; i++) {
    ans /= i;
  }
  while (pow_two != 0) {
    ans /= 2;
    pow_two--;
  }
  return ans;
}
vector<vector<int>> up;
int max_l, timer;
void dfs_lca(int v, int p, vector<vector<wor>>& g, vector<int>& tinn,
             vector<int>& toutt) {
  tinn[v] = timer;
  timer++;
  up[v][0] = p;
  for (int i = 1; i <= max_l; i++) {
    up[v][i] = up[up[v][i - 1]][i - 1];
  }
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].a;
    if (to == p) continue;
    dfs_lca(to, v, g, tinn, toutt);
  }
  toutt[v] = timer;
}
bool upper(int a, int b, vector<int>& tinn, vector<int>& toutt) {
  if (tinn[a] <= tinn[b] and toutt[a] >= toutt[b]) {
    return true;
  }
  return false;
}
int lca(int a, int b, vector<int>& tinn, vector<int>& toutt) {
  if (upper(a, b, tinn, toutt)) return a;
  if (upper(b, a, tinn, toutt)) return b;
  for (int i = max_l; i >= 0; i--) {
    if (!upper(up[a][i], b, tinn, toutt)) {
      a = up[a][i];
    }
  }
  return up[a][0];
}
long long phi(long long n) {
  long long ans = n;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) {
        n /= i;
      }
      ans -= ans / i;
    }
  }
  if (n != 1) {
    ans -= ans / n;
  }
  return ans;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> g(n);
  for (int i = 0; i < n; i++) {
    cin >> g[i];
  }
  vector<vector<long long>> ans;
  ans.push_back({g[0]});
  for (int i = 1; i < n; i++) {
    if (ans[ans.size() - 1][ans[ans.size() - 1].size() - 1] > g[i]) {
      ans.push_back({g[i]});
      continue;
    }
    int l = -1, r = ans.size() - 1;
    while (l + 1 < r) {
      int m = (l + r) / 2;
      if (ans[m][ans[m].size() - 1] > g[i]) {
        l = m;
      } else {
        r = m;
      }
    }
    ans[r].push_back(g[i]);
  }
  for (int i = 0; i < ans.size(); i++) {
    for (int j = 0; j < ans[i].size(); j++) {
      cout << ans[i][j] << " ";
    }
    cout << '\n';
  }
  return 0;
}
