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.util.*;
import java.io.*;

public class Main {
	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;
	private static long mod = 1000000000 + 7;
	private static long mod1 = 1000000000 + 9;
	private static int MAX=1000001;
	private static int block;
	private static LinkedList<Integer> list[];
	private static boolean Visited[];
	private static int set[];
	private static int count[];
	
	private static void soln(){
	int N;
	int T,X,g,s,m,big,small;
	long c=0,c1=0,c2=0;
	
	T=1;
	while(T>0)
	{
		N=nextInt();
        count = new int[N];
        list = new LinkedList[N];
        for(int i=0;i<N;i++)
        	list[i]=new LinkedList();
        X=nextInt();
        list[0].addFirst(X);
        count[0]++;
        big=0;
        small=0;
        for(int i=1;i<N;i++)
        {
        	g=big;
        	s=small;
        	X=nextInt();
        	while(s-g>1)
        	{
        		m=(s+g)/2;
        		if(X>list[m].element())
        			s=m;
        		else
        			g=m;
        	}
        	if(X>list[g].element() && X>list[s].element())
        	{
        		list[g].addFirst(X);
        	}
        	else
        		if(X<list[g].element() && X>list[s].element())
        		{
        			list[s].addFirst(X);
        		}
        		else
        			if(X<list[g].element() && X<list[s].element())
        			{
        				list[s+1].addFirst(X);
        				small++;
        				
        			}
        	
        }
        
        for(int i=0;i<N;i++)
        {
        	if(list[i].size()==0)
        		break;
        	while(list[i].size()!=0)
        	{
        		pw.print(list[i].pollLast() + " ");
        	}
        	pw.println();
        }
	
		
		T--;
		
	}
		
	}
	
	
	public static int dfs(int x)
	{
		int sum=0;
		int c=0;
		Visited[x]=true;
		for(Integer a:list[x])
		{
			if(!Visited[a])
			{
				dfs(a);
				for(Integer b:list[a])
				{
					if(b!=x)
					if(count[b]==0)
						count[a]=2;
				}
				
				c=0;
			}
		}
		
			
		return 0;
	}
	

	public static int bfs(int s)
	{
		 int count[] = new int[101];
		 count[100]=-1;
		 boolean Visited[] = new boolean[101];
		
		int c = 0;
		LinkedList<Integer> queue = new LinkedList<Integer>();
		
		Visited[s]=true;
		queue.add(s);
		
		
		while(queue.size()!=0)
		{
			
			s=queue.poll();
			c = count[s]+1;
			for(Integer x: list[s])
			{
				if(Visited[x]!=true)
				{
					Visited[x]=true;
					queue.add(x);
					count[x]=c;
				}
			}
		}
		
		return count[100];
		
	}
	
	
	
	
	
	
	
	public static class disjointunion
	{
		int parent[],rank[],number[];
		int n;
	public	disjointunion(int n){
			rank = new int[n];
			parent = new int[n];
			number = new int[n];
			this.n=n;
			makeset();
		}
  void makeset()
  {	
	  for(int i=0;i<n;i++)
	  {
		parent[i]=i;
		number[i]=1;
	  }
  }
	int find(int i)
	{
		if(parent[i]!=i)
		{
			parent[i]=find(parent[i]);
		}
			return parent[i];
	}
	void union(int x,int y)
	{
		int xRoot , yRoot;
		xRoot = find(x);
		yRoot = find(y);
		if(xRoot==yRoot)
		return;
		
		if(rank[xRoot]<rank[yRoot])
		{
			parent[xRoot]=yRoot;
			number[yRoot] += number[xRoot];
			number[xRoot]=0;
		}
		if(rank[xRoot]>rank[yRoot])
		{
			parent[yRoot]=xRoot;
			number[xRoot] += number[yRoot];
			number[yRoot]=0;
		}
		if(rank[xRoot]==rank[yRoot])
		{
			parent[xRoot]=yRoot;
			number[yRoot] += number[xRoot];
			number[xRoot]=0;
			rank[yRoot]++;
		}
	}
	}	
		
	public static void main(String[] args) throws Exception 
	{
		new Thread(null,new Runnable()
		{
			@Override
			public void run() 
			{
				InputReader(System.in);
				pw = new PrintWriter(System.out);
				soln();
				pw.close();
			}
		},"1",1<<26).start();
	}

	public static void InputReader(InputStream stream1)
	{
		stream = stream1;
	}

	private static boolean isWhitespace(int c) 
	{
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private static boolean isEndOfLine(int c)
	{
		return c == '\n' || c == '\r' || c == -1;
	}

	private static int read()
	{
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) 
		{
			curChar = 0;
			try 
			{
				numChars = stream.read(buf);
			} catch (IOException e) 
			{
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	private static int nextInt()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do 
		{
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static long nextLong() 
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do 
		{
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static String nextToken()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do 
		{
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private static String nextLine() 
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do 
		{
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n) 
	{
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) 
		{
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n)
	{
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) 
		{
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr) 
	{
		for (int i = 0; i < arr.length; i++) 
		{
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr)
	{
		for (int i = 0; i < arr.length; i++)
		{
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c) 
	{
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}
	private static char nextChar() 
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		char c1=(char)c;
		while(!isSpaceChar(c))
			c=read();
		return c1;
	}
	private interface SpaceCharFilter 
	{
		public boolean isSpaceChar(int ch);
	}
	
	
}