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 
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BPreparingForMergeSort solver = new BPreparingForMergeSort();
        solver.solve(1, in, out);
        out.close();
    }

    static class BPreparingForMergeSort {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int n = sc.nextInt();
            int[] arr = new int[n];
            TreeSet<Integer> set = new TreeSet<>();
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
                set.add(arr[i]);
            }
            HashMap<Integer, Integer> map = new HashMap<>();
            for (int x : set)
                map.put(x, map.size() + 1);
            int N = 1;
            while (N < map.size())
                N <<= 1;
            int[] in = new int[N + 1];
            Arrays.fill(in, (int) 1e9);
            for (int i = 0; i < n; i++) {
                in[map.get(arr[i])] = i;
            }
            SegmentTree sTree = new SegmentTree(in);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < n; i++) {
                if (sTree.query(map.get(arr[i]), map.get(arr[i])) == (int) 1e9)
                    continue;
                int prev = arr[i];
                while (sTree.query(map.get(prev), map.size()) != (int) 1e9) {
                    sb.append(arr[sTree.query(map.get(prev), map.size())] + " ");
                    int temp = arr[sTree.query(map.get(prev), map.size())];
                    sTree.update_point(map.get(temp), (int) 1e9);
                    prev = temp;
                }
                sb.append('\n');
            }
            pw.println(sb);
        }

        public class SegmentTree {
            int N;
            int[] array;
            int[] sTree;
            int[] lazy;

            SegmentTree(int[] in) {
                array = in;
                N = in.length - 1;
                sTree = new int[N << 1];        //no. of nodes = 2*N - 1, we add one to cross out index zero
                lazy = new int[N << 1];
                build(1, 1, N);
            }

            void build(int node, int b, int e) {
                if (b == e)
                    sTree[node] = array[b];
                else {
                    int mid = b + e >> 1;
                    build(node << 1, b, mid);
                    build(node << 1 | 1, mid + 1, e);
                    sTree[node] = Math.min(sTree[node << 1], sTree[node << 1 | 1]);
                }
            }

            void update_point(int index, int val) {
                index += N - 1;
                sTree[index] += val;
                while (index > 1) {
                    index >>= 1;
                    sTree[index] = Math.min(sTree[index << 1], sTree[index << 1 | 1]);
                }
            }

            int query(int i, int j) {
                return query(1, 1, N, i, j);
            }

            int query(int node, int b, int e, int i, int j) {
                if (i > e || j < b)
                    return (int) 1e9;
                if (b >= i && e <= j)
                    return sTree[node];
                int mid = b + e >> 1;
                int q1 = query(node << 1, b, mid, i, j);
                int q2 = query(node << 1 | 1, mid + 1, e, i, j);
                return Math.min(q1, q2);

            }

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

