According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.

Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. [Image] 

However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.

Write a program that models the behavior of Ankh-Morpork residents.


-----Input-----

The first line contains single integer n (1 ≤ n ≤ 100 000) — the total number of snacks.

The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n. 


-----Output-----

Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.


-----Examples-----
Input
3
3 1 2

Output
3
 
2 1
Input
5
4 5 1 2 3

Output
 
5 4
 
 
3 2 1



-----Note-----

In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.

Difficulty: interview

Starter code:

Solutions:
n = int(input())
a = list(map(int, input().split()))
s = set()
j = 0
i = n
while i != 0:
	if a[j] == i:
		print(i)
		j += 1
		i -= 1
	else:
		while j < n and a[j] != i:
			s.add(a[j])
			j += 1
			print()
		s.add(i)
		while i > 0 and i in s:
			print(i, end = ' ')
			i -= 1



#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input())
A = list(map(int, input().split()))
V = [False] * (n + 1)
p = n
for i in range(n):
  V[A[i]] = True
  p0 = p
  while V[p]:
    print(p, end=' ')
    p -= 1
  print()



n = int(input())
used = [False] * (n + 1)
num = list(map(int, input().split()))
cur = n
for i in range(0, n):
    x = num[i]
    used[x] = True
    while(used[cur]):
        print(cur, end = ' ')
        cur -= 1
    print('')
    

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
snacks = list(map(int, input().split()))
status = [False] * (n + 1)

biggest = n
for day, snack in enumerate(snacks):
    status[snack] = True
    ret = ''
    if biggest == snack:
        biggest -= 1
        while status[biggest] and biggest >= 1:
            biggest -= 1
        ret_list = list(range(biggest + 1, snack + 1))
        ret = ' '.join(map(str, reversed(ret_list)))
    print(ret)
            
            

    


n = int(input())
snacks = list(map(int, input().split()))
present = [0] * (n + 1)
exp = n
i = 0
for i in range(n):
    s = snacks[i]
    present[s] = 1
    curans = ''
    if s == exp:
        curans = str(exp) + ' '
        while exp - 1 > 0 and present[exp - 1]:
            curans += str(exp - 1) + ' '
            exp -= 1
        exp -= 1
    if curans:
        print(curans[:-1])
    else:
        print('')

# coding: utf-8

n = int(input())
a_s = map(int, input().split())

ad = {a:i for i, a in enumerate(a_s)}
cd = 0
st = []
for i in range(n, 0, -1):
    if ad[i] > cd:
        print(" ".join(st), end="")
        st = []
        print("\n" * (ad[i] - cd), end="")
        cd = ad[i]
    st.append(str(i))

print(" ".join(st))


from heapq import *

N = int(input().strip())
snacks = [int(x) for x in input().strip().split(' ')]

snacks_sorted = sorted(snacks)

buffer = []

for i in range(N):
    heappush(buffer, -snacks[i])
    while len(buffer) > 0 and -buffer[0] == snacks_sorted[-1]:
        snacks_sorted.pop()
        x = heappop(buffer)
        print(-x,"",end="")
    print()



#!/usr/bin/env python3
def ri():
    return map(int, input().split())

n = int(input())
a = ri()

b = set()

s = n

for aa in a:
    b.add(aa)
    if aa == s:
        print(s, end="")
        for ss in range(s-1, 0, -1):
            if ss == 0:
                print()
                return
            if ss in b:
                print(" ", end="")
                print(ss, end="")
            else:
                s = ss
                print()
                break
    else:
        print()

print()


import heapq

N = int(input())
ns = [int(x) for x in input().strip().split(' ')]

largest = N
storage = []

for n in ns:
    if n != largest:
        heapq.heappush(storage, -n)
        print()
    else:
        print(n, end=' ')
        largest -= 1
        while len(storage) > 0 and storage[0] == -largest:
            print(-heapq.heappop(storage), end=' ')
            largest -= 1

        print()


def solve(snecks):
	counted_snecks = []
	for i in range(len(snecks)):
		counted_snecks.append([snecks[i], i])
	counted_snecks = sorted(counted_snecks, key=lambda x: x[0], reverse=True)
	
	for i in range(1, len(counted_snecks)):
		if counted_snecks[i][1] < counted_snecks[i - 1][1]:
			counted_snecks[i][1] = counted_snecks[i - 1][1]
	return counted_snecks




def __starting_point():
	n = int(input())
	snecks = list(map(int, input().split()))
	
	counted_snecks = solve(snecks)

	printing_array = [[] for _ in range(len(counted_snecks))]

	for cs in counted_snecks:
		printing_array[cs[1]].append(cs[0])
	
	for el in printing_array:
		print(" ".join(list(map(str, el))))
		

__starting_point()

from sys import stdin as fin
# fin = open("cfr398a.in", "r")

n = int(fin.readline())
arr = list(map(int, fin.readline().split()))

pre = [False] * (n + 1)

maxab, l, r = n, 0, 0

for i in range(1, n + 1):
    pre[arr[i - 1]] = True
    if arr[i - 1] == maxab:
        while pre[maxab]:
            print(maxab, end=' ')
            pre[maxab] = False
            maxab -= 1
        print()
    else:
        print()

n=int(input())
s=set()
l=n
a=map(int,input().split())
for i in a:
    s.add(i)
    while l in s:
        print(l,end=' ')
        l-=1
    print()


__author__ = "Ryabchun Vladimir"


class Stack:
    """
    This is a stack class. There is 5 Procedures we can do with stack:
    1. Push - we add one element at the end of the stack
    2. Pop - we remove last element from the stack and return it
    3. Last - We return last element but don't remove it
    4. len() - returns the length of stack(we don't use len() because it's too
    slow).
    5. Clear - remove all elements from stack
    """
    def __init__(self, element=None):
        """
        self.length - length of the stack. When we append an element we increase it(length) by 1
        __stack - this is our stack. Because we can't get any elements from the stack except the last one
        we have to keep our stack as a private variable(we can receive any element - foo = Stack(); foo.stack[0] = 0,
        but we mustn't do it).
        :param element: Can be any type
        """
        self.length = 0
        if element is None:
            self.__stack = []
        else:
            self.__stack = []
            for el in element:
                self.__stack.append(el)
                self.length += 1

    def push(self, element):
        """
        This function adds an element at the end of the stack.
        When we append an element we increase self.length by 1.
        :param element: Can be any type
        :return: NoneType
        """
        self.__stack.append(element)
        self.length += 1

    def pop(self):
        """
        This function removes an element from the end of the stack and
        returns it's value.
        When we append an element we decrease self.length by 1.
        :return: Last element from the stack
        """
        if self.length == 0:
            raise IndexError("Stack is empty")
        else:
            self.length -= 1
            return self.__stack.pop()

    def last(self):
        """
        This function just returns an element from the end of the stack
        but it doesn't remove it.
        :return: Last element from the stack
        """
        if self.length == 0:
            raise IndexError("Stack is empty")
        else:
            return self.__stack[-1]

    def __len__(self):
        """
        This function returns the length of the stack.
        :return: self.length(int)
        """
        return self.length

    def clear(self):
        """
        Clears the stack.
        :return: NoneType
        """
        self.__stack = []

n = int(input())
snekovik = Stack()
wrong_snaks = set()
the_biggest_snek = n
sneks = list(map(int, input().split()))
for i in sneks:
    printing = []
    if i == the_biggest_snek:
        snekovik.push(i)
        printing.append(i)
        the_biggest_snek -= 1
        while the_biggest_snek in wrong_snaks:
            snekovik.push(the_biggest_snek)
            wrong_snaks.remove(the_biggest_snek)
            printing.append(the_biggest_snek)
            the_biggest_snek -= 1
    else:
        wrong_snaks.add(i)
    print(*printing)


n = int(input())
days = list(map(int,input().split()))
seen = set()
m = n
res = []
for k in range(n):
    res.append([])
for k in range(n):
    if days[k] == m:
        res[k].append(str(m))
        i = 1
        last = m
        while m-i in seen:
            res[k].append(str(m-i))
            last = last-1
            i += 1
        m = last-1
    else:
        seen.add(days[k])
for day in res:
    print(" ".join(day))


n = int(input())
snacks = map(int, input().split())
fall = [0] * (n + 1)
for snack in snacks:
    fall[snack] = 1
    output = []
    while fall[n] == 1:
        output.append(n)
        n -= 1
    print(' '.join(map(str, output)))

n = int(input());
a = list(map(int, input().split(' ')))
curr = n
s = set()
for x in a:
    s.add(x)

    l = []
    while n in s:
        l.append(n)
        s.remove(n)
        n -= 1

    print(' '.join(list(map(str, l))))


n = int(input())
arr = [0]+list(map(int, input().split()))
came = [False]*(n+2)
put = [False]*(n+2)
put[n+1], came[n+1] = True, True
for i in range(1,n+1):
	if put[arr[i]+1] == True:
		put[arr[i]] = True
		print(arr[i],end = ' ')
		k = arr[i]-1
		while came[k]:
			put[k] = True
			print(k,end = ' ')
			k -= 1
		print()
	else:
		came[arr[i]] = True
		print()


import sys
import heapq

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    n = int(input())
    A = [int(i) for i in input().split()]
    heap = []
    nxt = n

    for i in range(n):
        tmp = []
        heapq.heappush(heap, -A[i])
        while heap and -heap[0] == nxt:
            tmp.append(-heapq.heappop(heap))
            nxt -= 1
        print(*tmp)

def __starting_point():
    solve()
__starting_point()

n = int(input())
a = list(map(int, input().split()))
k = []
for i in range(len(a)):
    k.append((a[i], i + 1))
k.sort()
k=k[::-1]
curdate = 0
curpos = 0
while curpos < len(k):
    res = []
    res.append(k[curpos][0])
    for j in range(k[curpos][1] - curdate - 1):
        print()
    curdate = k[curpos][1]
    while curpos + 1 < len(k) and k[curpos + 1][1] <= curdate:
        curpos += 1
        res.append(k[curpos][0])
    curpos += 1
    print(*res)
        


import sys
n = int(input())
a = list(map(int, input().split()))
b = list(reversed(sorted(a)))
has = set()
l = 0
for i in range(n):
    if a[i] == b[l]:
        has.add(a[i])
        while l < n and b[l] in has :
            print(b[l], end = ' ')
            l += 1
        print()
    else:
        has.add(a[i])
        print()

n = int( input() )
L =  list( map(int,input().split())  )

exp = n ; 
T = [-1]*(n + 1)  ;

miss = 0
for i in range( len(L) ):
    T[ L[i] ] = i ;
    
ot = []    
for i in range(len(L)):
    if(L[i] == exp ):
       ot.append(exp)
       exp -= 1 
       while exp > 0 and T[exp] < i and T[exp] > -1 :
           ot.append(exp)
           exp -= 1
       print(*ot)
       ot = []
    else:
        print()


n = int(input())
x = list(map(int,input().split()))
e = n
my = set()
for i in range(0,n):
    my.add(x[i])
    if x[i] == e:
        while e in my:
            print(e,end=' ')
            my.remove(e)
            e = e - 1  
        print()
    else:
        print()
        
        
    

n = int(input())
a = list(map(int, input().split()))
done = set()
j = n
for i in range(n):
    done.add(a[i])
    while j in done:
        print(j, end=' ')
        j -= 1
    print()


n = int(input())
maxsn = n-1
a = list(map(int, input().split()))
snacks = [0] * 100001
for i in range(n):
    snacks[a[i]-1] = 1
    while snacks[maxsn] == 1:
        snacks[maxsn] = 0
        print(maxsn + 1, end=' ')
        maxsn -= 1
    print()


n = int(input())
lst = list(map(int,input().split()))
# lst = [int(i) for i in list(input()) if i!=' ']
# print(lst)
st = set()
idx = n
for i in range(len(lst)):
    x = lst[i]
    if x == idx:
        pt = [x]
        # print(pt)
        idx-=1
        while idx in st:
            pt.append(idx)
            idx-=1
        print(' '.join([str(i) for i in pt]))
    else:
        print()
        st.add(x)