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: EASY

Solutions:
n = int(input())
lt = list(input().split())
for i in range(n):
	lt[i] = int(lt[i])
lt2 = sorted(lt, reverse=True)
j = 0
D = {}
for i in range(n):
	s = ''
	D[lt[i]] = 1
	while j < n and lt2[j] in D:
		s += str(lt2[j]) + ' '
		j += 1
	print(s)


n = int(input())
n_1 = n
v = [int(x) for x in input().split()]
a = set()
for i in v:
	a.add(i)
	while n_1 in a:
		print(n_1, end=' ')
		n_1 -= 1
	print()


n = int(input())
(i, p) = (0, 0)
mapping = [0] * n
snack = []
for a in input().split(' '):
	snack.append(int(a))
	mapping[int(a) - 1] = i
	i += 1
for d in range(n):
	for i in range(p, n):
		if mapping[n - i - 1] > d:
			p = i
			break
		else:
			print(snack[mapping[n - i - 1]], end=' ')
	print('')


n = int(input())
snacks = list(map(int, input().split(' ')))
ja_foram = [0] * n
falta = n

def procurar(v, valor):
	retorno = ''
	if v == valor:
		for i in range(valor - 1, -1, -1):
			if ja_foram[i] > 0:
				retorno += '%s ' % (i + 1)
				ja_foram[i] = 0
				valor = i
			else:
				break
	print(retorno)
	return valor
for s in snacks:
	ja_foram[s - 1] = 1
	falta = procurar(s, falta)


(n, s) = (int(input()), set())
for a in map(int, input().split()):
	s.add(a)
	while True:
		try:
			s.remove(n)
		except KeyError:
			print()
			break
		else:
			print(n, end=' ')
			n -= 1


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


days = int(input())
entry = input()
snacks = list(map(int, entry.split(' ')))
store = [None] * days
for (i, snack) in enumerate(snacks):
	store_position = snack - 1
	if snack == days:
		print(snack, end=' ')
		days = days - 1
		while store[store_position - 1] != None and store_position > -1:
			print(store[store_position - 1], end=' ')
			store_position = store_position - 1
			days = days - 1
		print('')
	else:
		store[store_position] = snack
		if snack != snacks[-1]:
			print('')
need_print = False
for i in range(days - 1, 0, -1):
	need_print = True
	print(i, end=' ')
if need_print:
	print('')


n = int(input())
sett = set()
arr = map(int, input().split())
for snack in arr:
	sett.add(snack)
	while n in sett:
		print(n, end=' ')
		n -= 1
	print('')


n = int(input())
a = list(map(int, input().split()))
next = max(a)
has = [0] * 200001
for i in a:
	if i != next:
		has[i] += 1
		print()
	else:
		has[next] += 1
		while has[next]:
			print(next, end=' ')
			next -= 1
		print()


n = int(input())
res = n
found = [False for i in range(n + 1)]
lst = [int(v) for v in input().split(' ')]
i = 0
while i < n:
	v = lst[i]
	found[v] = True
	if found[res]:
		print('{} '.format(res), end='')
		res -= 1
		i -= 1
	else:
		print()
	i += 1
for v in range(res, 0, -1):
	print('{} '.format(v), end='')


n = int(input())
t = n
l = [0] * n
x = list(map(int, input().split()))
k = 0
for i in range(0, n):
	l[x[k] - 1] = 1
	k += 1
	j = t - 1
	while j > -1 and l[j] == 1:
		print(t, end=' ')
		t -= 1
		j -= 1
	if i != n - 1:
		print()


numberOfsnacks = int(input())
snacksSize = list(map(int, input().split()))
listOfsize = set()
size = numberOfsnacks
for i in range(len(snacksSize)):
	listOfsize.add(snacksSize[i])
	while size in listOfsize:
		print(size, end=' ')
		size -= 1
	print('')


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


last = n = int(input())
a = list(map(int, input().split()))
used = [False for i in range(n + 1)]
for i in range(n):
	used[a[i]] = True
	while last > 0:
		if used[last]:
			print(last, end=' ')
			last -= 1
		else:
			break
	print('')


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


N = int(input())
A = list(map(int, input().split()))
next = N
has = [False] * (N + 1)
for dayv in A:
	has[dayv] = True
	if dayv == next:
		while has[next]:
			print(next, end=' ')
			next = next - 1
	print()


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


n = int(input())
a = [int(q) for q in input().split()]
s = set()
m = n
for i in range(n):
	s.add(a[i])
	while m > 0 and m in s:
		print(m, end=' ')
		m -= 1
	print()


from sys import stdin, stdout
from collections import defaultdict
import heapq

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()
INF = 10000000000.0
n = get_int()
ar = get_array()
has = [0] * (n + 1)
maxs = n
for i in ar:
	has[i] = 1
	if i == maxs:
		j = i
		while j > 0 and has[j] == 1:
			print(j, end=' ')
			has[j] = 0
			maxs -= 1
			j = j - 1
	print()


n = int(input())
l = list(map(int, input().split()))
(vis, need) = ([False] * n, n)
for i in range(n):
	vis[l[i] - 1] = True
	if l[i] == need:
		for j in range(l[i] - 1, -1, -1):
			if not vis[j]:
				break
			print(j + 1, end=' ')
			need -= 1
	print()


n = int(input())
values = list(map(int, input().split()))
nextv = n
has = [0] * (n + 1)
for x in values:
	has[x] = 1
	if x == nextv:
		for i in range(nextv, -1, -1):
			if has[i] == 1:
				print(i, end=' ')
				nextv -= 1
				has[i] = 0
			else:
				break
	print()


def arr_enu():
	return [[i, int(x)] for (i, x) in enumerate(input().split())]

def arr_inp():
	return [int(x) for x in input().split()]

def print_arr(arr):
	print(*arr, sep=' ')

def fill_arr0(n):
	return [0 for x in range(n)]
(n, a) = (int(input()), arr_inp())
track = fill_arr0(100001)
ix = n
for i in range(n):
	track[a[i]] = 1
	while track[ix] and ix > 0:
		print(ix, end=' ')
		ix -= 1
	print()


n = int(input())
ara = list((int(i) for i in input().split()))
marker = list((int(0) for i in range(n)))
st = n
for i in range(n):
	if ara[i] == st:
		marker[ara[i] - 1] = 1
		while marker[st - 1] != 0 and st >= 1:
			print(st, end=' ')
			st -= 1
		print()
	else:
		marker[ara[i] - 1] = 1
		print()


import heapq
cmax = int(input())
rain = list(map(int, input().split()))
stack = []
for snack in rain:
	heapq.heappush(stack, -snack)
	out = ''
	while len(stack) > 0 and stack[0] == -cmax:
		cmax = cmax - 1
		out = out + '{0} '.format(-heapq.heappop(stack))
	print(out)


def Main():
	line = input().split()
	n = int(line[0])
	line = [int(x) for x in input().split()]
	copyLine = [int(x) for x in line]
	used = [0 for i in range(n + 1)]
	copyLine.sort()
	copyLineSize = n
	for i in range(n):
		used[line[i]] = 1
		if line[i] != copyLine[-1]:
			print('')
		else:
			while used[copyLine[-1]] == 1:
				print(copyLine[-1], end=' ')
				used[copyLine[-1]] = 2
				copyLine.pop()
				copyLineSize -= 1
				if copyLineSize == 0:
					break
			print('')
Main()


n = int(input())
snacks = list(map(int, input().split()))
notplaced = set()
for snack in snacks:
	if snack == n:
		print(snack, end=' ')
		n -= 1
		while n in notplaced:
			print(n, end=' ')
			n -= 1
	else:
		notplaced.add(snack)
	print()


def main():
	n = int(input())
	arr = [int(x) for x in input().split()]
	dic = set()
	curr_max = n
	for a in arr:
		dic.add(a)
		while curr_max in dic:
			print(curr_max, end=' ')
			curr_max -= 1
		print()
main()


from heapq import heappush, heappop
n = int(input())
candies = [int(x) for x in input().split(' ')]
sorted_candies = candies[:]
sorted_candies.sort()
sorted_candies = sorted_candies[::-1]
counter = {candy: 0 for candy in candies}
next_candy_index = 0
for (day, candy) in enumerate(candies):
	counter[candy] += 1
	next_candy = sorted_candies[next_candy_index]
	if candy == next_candy:
		while next_candy_index <= day and counter[next_candy] > 0:
			print(next_candy, end=' ')
			counter[next_candy] -= 1
			next_candy_index += 1
			if next_candy_index == len(candies):
				break
			else:
				next_candy = sorted_candies[next_candy_index]
	print('')


n = int(input())
A = list(map(int, input().split()))
B = [0] * (n + 1)
k = n
for i in range(n):
	B[A[i]] = 1
	if A[i] == k:
		while B[k] == 1:
			print(k, end=' ')
			k -= 1
		print()
	else:
		print()


n = int(input())
nextSnack = n
pending = {}
snacks = list(map(int, input().split()))
for i in range(0, n):
	if nextSnack == snacks[i]:
		print(snacks[i], end=' ')
		nextSnack -= 1
		while pending.get(nextSnack, 0) != 0:
			print(pending.get(nextSnack), end=' ')
			nextSnack -= 1
	else:
		pending[snacks[i]] = snacks[i]
	print('')


class CodeforcesTask767ASolution:

	def __init__(self):
		self.result = ''
		self.part_count = 0
		self.parts = []

	def read_input(self):
		self.part_count = int(input())
		self.parts = [int(x) for x in input().split(' ')]

	def process_task(self):
		ava_parts = [False for x in range(self.part_count)]
		level = self.part_count
		for (i, part) in enumerate(self.parts):
			ava_parts[part - 1] = True
			for x in range(level, 0, -1):
				if ava_parts[x - 1]:
					print(str(x), end=' ')
					ava_parts[x - 1] = False
					level -= 1
				else:
					break
			print('\n', end='')

	def get_result(self):
		return self.result
Solution = CodeforcesTask767ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n = int(input())
vs = [0 for i in range(n + 1)]
v = [int(x) for x in input().split()]
x = n
for i in v:
	vs[i] = 1
	while x > 0 and vs[x] > 0:
		print(x, end=' ')
		x -= 1
	print()


n = int(input())
l = [int(x) for x in input().split()]
found = [False] * (n + 1)
rn = n
c = n
for i in l:
	found[i] = True
	while found[c] and c > 0:
		print(c, end=' ')
		c -= 1
	print()


n = int(input())
lst = list(map(int, input().split()))
s = max(lst)
land = [0] * n
for i in range(len(lst)):
	land[lst[i] - 1] = 1
	if land[s - 1] == 1:
		while land[s - 1] == 1 and s > 0:
			print(s, end=' ')
			s -= 1
		print()
	else:
		print()


import sys
import math
input = sys.stdin.readline
n = int(input())
p = [0] * (n + 1)
c = list(map(int, input().strip().split(' ')))
last = n
for i in c:
	p[i] = 1
	if i == last:
		while 1:
			if p[last] == 1:
				print(last, end=' ')
			else:
				break
			last -= 1
	print()


n = int(input())
a = [-1] * n
b = []
s = map(int, input().split())
for i in s:
	b.append(i)
j = n - 1
for i in range(0, n):
	a[b[i] - 1] = 1
	while j >= 0 and a[j] == 1:
		print(j + 1, end=' ')
		j = j - 1
	print()


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


def toweradd(sn):
	tower.append(sn)
	print(sn, end=' ')
n = int(input())
tower = [n + 1]
zam = [0] * (n + 1)
for sn in map(int, input().split()):
	zam[sn] = 1
	big = tower[-1] - 1
	while zam[big] == 1:
		toweradd(big)
		big -= 1
	print()


n = int(input())
l = list(map(int, input().split()))
passed = [False] * (n + 1)
a = n
for i in range(n):
	passed[l[i]] = True
	for j in range(a, 0, -1):
		if passed[j]:
			print(j, end=' ')
		else:
			a = j
			break
	print()


n = int(input())
has = [False] * n
nxt = n
snack = list(map(int, input().split()))
for i in snack:
	has[i - 1] = True
	if i == nxt:
		j = nxt - 1
		while j < n and j > -1 and has[j]:
			print(j + 1, end=' ')
			j -= 1
		print()
		nxt = j + 1
	else:
		print()


n = int(input())
arr = list(map(int, input().split()))
marked = [None] + [False for i in range(n)]
j = n
for i in range(n - 1):
	marked[arr[i]] = True
	if arr[i] == j:
		k = j
		while marked[k] and k > 0:
			print(k, end=' ')
			k -= 1
		j = k
		print()
	else:
		print()
for i in range(j, 0, -1):
	print(i, end=' ')


from heapq import heappush, heappop

class MaxHeapObj(object):

	def __init__(self, val):
		self.val = val

	def __lt__(self, other):
		return self.val > other.val

	def __eq__(self, other):
		return self.val == other.val

	def __str__(self):
		return str(self.val)
n = int(input())
maxHeap = []
for d in input().split():
	i = int(d)
	if i == n:
		print(i, end=' ')
		n -= 1
		while maxHeap and maxHeap[0].val == n:
			print(heappop(maxHeap), end=' ')
			n -= 1
		print()
	else:
		heappush(maxHeap, MaxHeapObj(i))
		print()


n = int(input())
l = list(map(int, input().split()))
count = n
d = dict()
for i in range(n):
	d[l[i]] = i
i = 0
while i < n:
	if l[i] == count and d[l[i]] != None:
		for j in range(l[i], 0, -1):
			if d[j] <= i:
				print(j, end=' ')
				d[j] = None
				count -= 1
			else:
				break
		print()
	else:
		print()
	i += 1
for j in range(n, 0, -1):
	if d[j] != None:
		print(j, end=' ')


n = input()
snacks = list(map(int, input().split()))
stack = [0] * (int(n) + 1)
counter = int(n)
for i in range(int(n), 0, -1):
	if snacks[int(n) - i] == counter:
		stack[counter] = 1
		while stack[counter] == 1:
			print(counter, end=' ')
			counter -= 1
			if counter == 0:
				break
		if i != 1:
			print()
	else:
		stack[snacks[int(n) - i]] = 1
		print()


n = int(input())
l = list(map(int, input().split()))
h = []
k = [0] * (n + 1)
s = n
for i in l:
	k[i] = 1
	a = i
	h1 = []
	while a == s and k[a] == 1:
		h1.append(s)
		a -= 1
		s -= 1
	h.append(h1)
for i in range(len(h)):
	for j in range(len(h[i])):
		print(h[i][j], end=' ')
	print()


n = int(input())
l = list(map(int, input().split()))
mask = [0] * (n + 1)
index = n
for i in l:
	mask[i] = 1
	while mask[index] == 1:
		print('{} '.format(index), end='')
		index -= 1
	print()


n = int(input())
arr = list(map(int, input().split()))
arr = [(arr[i], i) for i in range(n)]
arr = sorted(arr, reverse=True)
k = 0
for i in range(n):
	idx = arr[i][1]
	while idx > k:
		print()
		k += 1
	print(arr[i][0], end=' ')


n = int(input())
a = list(map(int, input().split()))
k = n
l = {}
for i in range(1, n + 1):
	l[i] = 0
for i in a:
	if i == k:
		print(i, end=' ')
		k -= 1
		while 1:
			if k in l and l[k] == 1:
				print(k, end=' ')
				l[k] = 0
				k -= 1
			else:
				print()
				break
	else:
		print()
		l[i] = 1


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


n = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
b = []
for i in range(n + 1):
	b.append(False)
c = n
for i in range(1, n + 1):
	b[a[i]] = True
	while b[c]:
		print(c, end=' ')
		c = c - 1
	print()


def Add(ele, List):
	N = len(List)
	(L, R) = (0, N - 1)
	mid = (L + R) // 2
	while L <= R:
		if List[mid] > ele:
			if mid - 1 >= 0:
				if List[mid - 1] < ele:
					List[mid - 1] = ele
n = int(input())
List = [0 for i in range(n - 1)]
curr_max = n
arr = list(map(int, input().split()))
L = n - 1
l = len(List)
prev = False
for num in arr:
	if num == curr_max:
		print(num, end=' ')
		while l > 0 and List[-1] != 0:
			print(List.pop(), end=' ')
			prev = True
			l -= 1
		if l > 0:
			List.pop()
		l -= 1
		print()
		curr_max = l + 1
	else:
		List[num - 1] = num
		print()
		prev = False


n = int(input())
l = list(map(int, input().split()))
v = [0] * n
x = n
for i in l:
	v[i - 1] = 1
	while x > 0 and v[x - 1] > 0:
		print(x, end=' ')
		x -= 1
	print()


n = int(input())
s = [int(x) for x in input().split()]
import heapq
hold = []
for i in s:
	heapq.heappush(hold, -i)
	if -1 * hold[0] == n:
		while len(hold) != 0 and -1 * hold[0] == n:
			print(n, end=' ')
			n -= 1
			heapq.heappop(hold)
		print()
	else:
		print()


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())
vis = set()
a = list(map(int, input().split(' ')))
for i in range(n):
	vis.add(a[i])
	while n in vis:
		print(n, end=' ')
		n -= 1
	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()


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


n = int(input())
a = list(map(int, input().split()))
b = [0] * n
j = n - 1
for i in a:
	b[i - 1] = 1
	while j >= 0 and b[j] == 1:
		print(j + 1, end=' ')
		j += -1
	print()


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


N = int(input())
order = []
for num in input().split():
	order.append(num)
s = set()
for num in order:
	s.add(int(num))
	while N in s:
		print(N, end=' ')
		s.remove(N)
		N -= 1
	print()


n = int(input())
a = input().split()
b = []
for i in range(n):
	b.append([int(a[i]), i])
b.sort(reverse=True)
k = 0
for i in range(n):
	if b[i][1] > k:
		for j in range(k, b[i][1]):
			print()
		k = b[i][1]
		print(b[i][0], end=' ')
	else:
		print(b[i][0], end=' ')


n = int(input())
arr = [int(i) for i in input().split()]
l = [0] * (n + 1)
k = n
for i in range(n):
	l[arr[i]] = 1
	while l[k] == 1:
		print(k, end=' ')
		k -= 1
	else:
		print('')


n = int(input())
s = input()
s = s.split()
for i in range(len(s)):
	s[i] = int(s[i])
temp = n
x = [0] * (n + 1)
for i in s:
	x[i] = 1
	while x[n]:
		print(n, end=' ')
		n -= 1
	print()


n = int(input())
x = list(map(int, input().split()))
a = n * [0]
pointer = 0
abc = n
for i in range(n):
	a[-x[i]] = x[i]
	if x[i] != abc:
		print()
	else:
		print(abc, end=' ')
		pointer += 1
		abc -= 1
		if abc < 1:
			break
		while a[pointer] == abc:
			print(a[pointer], end=' ')
			pointer += 1
			abc -= 1
			if abc == 0:
				exit()
		print('')


n1 = int(input())
temp = n1
list1 = [int(x) for x in input().split()]
list2 = [False] * (n1 + 1)
count = 1
for i in range(temp):
	if n1 == list1[i]:
		print(n1, end=' ')
		n1 -= 1
		while True:
			if list2[n1] == True:
				print(n1, end=' ')
				n1 -= 1
			else:
				break
		if n1 != 0:
			print()
	else:
		print()
		list2[list1[i]] = True


n = int(input())
c = list(map(int, input().split()))
p = set()
l = n
for i in range(n):
	p.add(c[i])
	while l in p and l > 0:
		print(l, end=' ')
		l -= 1
	print()


n = int(input())
snacks = input().split(' ')
lsnack = []
start = 0
for snack in snacks:
	lsnack.append(int(snack))
order = sorted(lsnack, reverse=True)
HaveSeen = dict(zip(order, [0 for i in range(n)]))
for j in range(n):
	HaveSeen[lsnack[j]] = 1
	k = start
	while k < n and HaveSeen[order[k]] == 1:
		print(order[k], end=' ')
		k += 1
	print('')
	start = k


n = int(input())
a = list(map(int, input().split()))
has = []
for i in range(n):
	has.append(0)
next = n
for i in a:
	if i == next:
		print(i, end=' ')
		next -= 1
		while has[next - 1] == 1:
			print(next, end=' ')
			next -= 1
		print()
	else:
		print()
		has[i - 1] = 1


from sys import stdin
n = int(stdin.readline().rstrip())
s = set()
l = list(map(int, stdin.readline().split()))
j = n
for i in l:
	s.add(i)
	while j in s:
		print(str(j) + ' ', end='')
		j -= 1
	print()


n = int(input())
List = [int(x) for x in input().split()]
Visited = [False] * n
Searching = n
for i in range(n):
	if List[i] == Searching:
		Visited[List[i] - 1] = True
		for x in range(Searching - 1, -1, -1):
			if Visited[x] == True:
				print(x + 1, end=' ')
			else:
				print()
				Searching = x + 1
				break
	else:
		Visited[List[i] - 1] = True
		print()


from sys import stdin as fin
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())
days = map(int, input().split())
each = set()
for i in days:
	each.add(i)
	while n in each:
		print(n, end=' ')
		n -= 1
	print()


from sys import stdin
input = stdin.readline
a = input()
arr = list(map(int, input().strip().split()))
cmax = len(arr)
stack = [0] * (len(arr) + 2)
n = len(arr)
for i in arr:
	stack[i] = 1
	while stack[n]:
		print(n, end=' ')
		n -= 1
	print('')


import heapq as hq
n = int(input())
l = list(map(int, input().split()))
q = []
c = n
for i in range(n):
	hq.heappush(q, -1 * l[i])
	if -1 * q[0] == c:
		while q and -1 * q[0] == c:
			print(-1 * hq.heappop(q), end=' ')
			c -= 1
		print()
	else:
		print()


n = int(input())
buffer = list(map(int, input().split()))
next = n
wait = set()
for i in range(n):
	a = buffer.pop(0)
	wait.add(a)
	while next in wait:
		wait.remove(next)
		print(next, end=' ')
		next -= 1
	print('\n', end='')


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def createMatrix(rowCount, colCount, dataList):
	mat = []
	for i in range(rowCount):
		rowList = []
		for j in range(colCount):
			if dataList[j] not in mat:
				rowList.append(dataList[j])
		mat.append(rowList)
	return mat

def isprime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
import collections

def minimalFilps1(bits):
	n = len(bits)
	flipsFromLeft = [0 for i in range(n)]
	flipsFromRight = [0 for i in range(n)]
	flips = 0
	for i in range(0, n, 1):
		if bits[i] == '1':
			flips = flips + 1
		flipsFromLeft[i] = flips
	flips = 0
	i = n - 1
	while i >= 0:
		if bits[i] == '0':
			flips = flips + 1
		i = i - 1
		flipsFromRight[i] = flips
	minFlips1 = sys.maxsize
	for i in range(1, n, 1):
		if flipsFromLeft[i - 1] + flipsFromRight[i] < minFlips1:
			minFlips1 = flipsFromLeft[i - 1] + flipsFromRight[i]
	return minFlips1

def minimalFilps(bits):
	n = len(bits)
	flipsFromLeft = [0 for i in range(n)]
	flipsFromRight = [0 for i in range(n)]
	flips = 0
	for i in range(0, n, 1):
		if bits[i] == '0':
			flips = flips + 1
		flipsFromLeft[i] = flips
	flips = 0
	i = n - 1
	while i >= 0:
		if bits[i] == '1':
			flips = flips + 1
		i = i - 1
		flipsFromRight[i] = flips
	minFlips = sys.maxsize
	for i in range(1, n, 1):
		if flipsFromLeft[i - 1] + flipsFromRight[i] < minFlips:
			minFlips = flipsFromLeft[i - 1] + flipsFromRight[i]
	return minFlips

def oddn(n):
	for i in range(2, n + 1):
		if i % 2 != 0 and n % i == 0:
			return i
	return 3
n = int(inp())
a = list(map(int, inp().split()))
b = [0] * (n + 1)
c = []
d = n
for i in range(n):
	b[a[i]] = 1
	while b[d] and d > 0:
		print(d, end=' ')
		d -= 1
	print()


n = int(input())
save = [0] * (n + 1)
arr = list(map(int, input().split()))
largest = n
for i in arr:
	save[i] = 1
	while save[largest] == 1:
		print(largest, end=' ')
		largest -= 1
	print()


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()


import sys
n = int(input())
s = [int(i) for i in input().split()]
next = n
a = (n + 1) * [bool]
for p in s:
	a[p] = 1
	while a[next] == 1:
		print(next, end=' ')
		next -= 1
	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())
line = input().split()
nextEl = n
board = []
for i in range(0, n):
	board.append(0)
for word in line:
	snack = int(word)
	board[snack - 1] = 1
	if snack == nextEl:
		while board[nextEl - 1] == 1 and nextEl > 0:
			print(nextEl, end=' ')
			nextEl = nextEl - 1
	print()


n = int(input())
snacks = list(map(int, input().split(' ')))
fallen = [0] * (n + 1)
current = n
for i in range(0, n):
	fallen[snacks[i]] = 1
	if fallen[current] == 1:
		while fallen[current] != 0:
			print(current, '', end='')
			current -= 1
		print()
	else:
		print()


n = int(input())
l = list(map(int, input().split()))
a = [0 for i in range(n)]
j = n - 1
for i in range(n):
	a[l[i] - 1] = 1
	while j >= 0 and a[j] == 1:
		print(j + 1, end=' ')
		j -= 1
	else:
		print()
while j >= 0:
	print(j + 1, end=' ')
	j -= 1


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


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


n = int(input())
l1 = list(map(int, input().split()))
l = [0] * n
current = n

def printer(x, current2):
	if x == current2:
		for i in range(current2, 0, -1):
			if l[i - 1] == 1:
				print(i, end=' ')
				global current
				current = i - 1
			else:
				break
for i in range(n):
	x = l1[i]
	l[x - 1] = 1
	printer(x, current)
	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()


totalNoOfSnacks = int(input())
snacksSizeListOnIthDay = [int(x) for x in input().split(' ')]
dictOfPossibleNumbersReceivedStatus = {x: False for x in snacksSizeListOnIthDay}
currentMaxSnackSize = totalNoOfSnacks
for i in range(totalNoOfSnacks):
	dictOfPossibleNumbersReceivedStatus[snacksSizeListOnIthDay[i]] = True
	while currentMaxSnackSize > 0 and dictOfPossibleNumbersReceivedStatus[currentMaxSnackSize]:
		print(currentMaxSnackSize, end=' ')
		currentMaxSnackSize -= 1
	print()


from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = getInt()
arr = zzz()
x = n
s = set()
for i in range(n):
	s.add(arr[i])
	while x in s:
		print(x, end=' ')
		x -= 1
	print()


first = input()
n = int(first)
second = input()
nums = [int(x) for x in second.split()]
stack = set()
for num in nums:
	stack.add(num)
	while len(stack) > 0 and n in stack:
		print(n, end=' ')
		n -= 1
	print()


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


n = int(input())
nums = list(map(int, input().rstrip().split()))
chk = []
index = n
for i in range(n):
	chk.append(False)
for i in range(n):
	chk[nums[i] - 1] = True
	while chk[index - 1] and index > 0:
		print(index, end=' ')
		index -= 1
	print()


n = int(input())
a = list(map(int, input().split()))
l = []
mx = max(a)
m = {}
for i in range(n):
	m[a[i]] = 0
for i in range(n):
	m[a[i]] = 1
	if a[i] == mx:
		print(a[i], end=' ')
		mx = a[i] - 1
	while mx in m.keys() and m[mx] != 0:
		print(mx, end=' ')
		mx = mx - 1
	print()


_ = input()
n = list(map(int, input().rstrip().split()))
n.insert(0, 0)
seen = [False] * len(n)
m = len(n) - 1
s = ''
for i in range(1, len(n)):
	seen[n[i]] = True
	while seen[m] and m > 0:
		print(str(m), end=' ')
		m -= 1
	print('')


n = int(input())
digits = list(map(int, input().split(' ')))[:n]
que = set()
while digits != []:
	que.add(digits.pop(0))
	while n in que and n > 0:
		print(n, end=' ')
		n -= 1
	print('')


n = int(input())
carry = []
li = [int(x) for x in input().split()]
for i in li:
	if i == n:
		print(i, end=' ')
		n -= 1
		while n in carry:
			print(n, end=' ')
			n -= 1
		print()
	else:
		print()
		carry.append(i)


n = int(input())
day = list(map(int, input().split()))
arr = [False] * (n + 1)
m = n
for item in day:
	arr[item] = True
	if item == m:
		for i in range(n):
			if arr[m - i]:
				print(m - i, end=' ')
			else:
				m = m - i
				break
	print()


n = int(input())
stone = list(map(int, input().split()))
h = set()
for i in stone:
	h.add(i)
	while n in h and n > 0:
		print(n, end=' ')
		n -= 1
	print()


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


tmp = set()
size = int(input())
ns = list(map(int, input().split()))
for x in ns:
	tmp.add(x)
	while size in tmp:
		print(size, end=' ')
		size -= 1
	print()


def read():
	n = input()
	n = int(n)
	l = input().split(' ')
	return l

def solve():
	l = read()
	n = len(l)
	fr = 100000 * [0]
	if n == 1:
		print(1)
	elif n == 2 and l[1] == '1':
		print(2)
		print(1)
	else:
		for i in range(n):
			if int(l[i]) == n:
				lis = []
				lis.append(l[i])
				ele = int(l[i])
				if i == len(l) - 1 and lis[0] == '1':
					print(1)
				for j in range(ele - 1, 0, -1):
					if fr[j] == 1:
						lis.append(j)
						fr[j] = 0
					else:
						for ele in lis:
							print(ele, end=' ')
						print()
						n = j
						break
					if j == 1:
						for ele in lis:
							print(ele, end=' ')
						print()
						n = j
			else:
				fr[int(l[i])] = 1
				print()
solve()


def print_snacks(appeared, curr_snack, required_snack):
	appeared[curr_snack] = 1
	if curr_snack == required_snack:
		while appeared[curr_snack] == 1 and curr_snack >= 0:
			print(curr_snack + 1, end=' ')
			curr_snack -= 1
		required_snack = curr_snack
	return required_snack
n = int(input())
snacks = input().split(' ')
for i in range(n):
	snacks[i] = int(snacks[i])
appeared = [0] * n
required_snack = n - 1
for i in range(n):
	required_snack = print_snacks(appeared, snacks[i] - 1, required_snack)
	if i != n - 1:
		print('')


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


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


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


n = int(input())
vls = list(map(int, input().split()))
temp = set()
mx = n
for x in vls:
	temp.add(x)
	while mx in temp:
		print(mx, end=' ')
		mx -= 1
	print()


def solution():
	n = int(input())
	snacks = [int(i) for i in input().split()]
	visited = set()
	pointer = n
	for snack in snacks:
		visited.add(snack)
		while pointer > 0:
			if pointer in visited:
				print(pointer, end=' ')
				pointer -= 1
			else:
				print()
				break
solution()


n = int(input())
l1 = [0] * (n + 1)
l2 = list(map(int, input().split()))
l2.insert(0, 0)
next1 = n
for i in range(1, n + 1):
	x = l2[i]
	l1[x] = 1
	while l1[next1] == 1:
		print(next1, end=' ')
		next1 -= 1
	print('')


import sys
have = []
n = int(input())
up = n
for i in range(n + 1):
	have.append(False)
a = list(map(int, sys.stdin.readline().split()))
for i in range(n):
	x = a[i]
	have[x] = True
	while up > 0 and have[up]:
		print(up, end=' ')
		up = up - 1
	print()


n = int(input())
snacks = [int(x) for x in input().split()]
skipped = set()
for snack in snacks:
	skipped.add(snack)
	while n in skipped:
		print(n, end=' ')
		n -= 1
	print()


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


n = int(input())
snacks = list(map(int, input().split()))
next_need = n
got_elems = [0] * 10 ** 5
for i in range(n):
	if snacks[i] == next_need:
		print(snacks[i], end=' ')
		next_need -= 1
		while got_elems[next_need - 1]:
			print(next_need, end=' ')
			next_need -= 1
		print('')
	else:
		got_elems[snacks[i] - 1] = 1
		print('')


n = int(input())
s = set()
li = [int(x) for x in input().split()]
for i in li:
	s.add(i)
	while n in s:
		print(n, end=' ')
		n -= 1
	print()


import heapq
n = int(input())
a = [int(x) for x in input().split()]
expected = n
stored = []
heapq.heapify(stored)
for ai in a:
	if ai != expected:
		print()
		heapq.heappush(stored, -ai)
	else:
		print(f'{ai} ', end='')
		expected -= 1
		if not stored:
			print()
			continue
		while stored:
			q = -heapq.heappop(stored)
			if q != expected:
				heapq.heappush(stored, -q)
				break
			print(f'{q} ', end='')
			expected -= 1
		print()
while stored:
	q = -heapq.heappop(stored)
	print(f'{q} ', end='')


(N, X) = (int(input()), list(map(int, input().split())))
(Check, Index) = ([False] * N, N)
for i in range(N):
	Check[X[i] - 1] = True
	while Index > 0 and Check[Index - 1]:
		print(Index, end=' ')
		Index -= 1
	print()


n = int(input())
arr = list(map(int, input().split()))
m = dict()
cnt = 1
for i in arr:
	m[i] = cnt
	cnt += 1
t = n
prev = 1
while t > 0:
	k = m[t]
	i = prev
	if prev == 1:
		while i < k:
			print()
			i += 1
	else:
		while i < k:
			print()
			i += 1
	prev = m[t]
	while m[t] <= k:
		print(t, end=' ')
		t -= 1
		if t == 0:
			break


def solution():
	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()
solution()


def main():
	n = int(input())
	cin = input().split()
	arr = list((False for i in range(n)))
	z = n - 1
	for i in cin:
		a = int(i)
		arr[a - 1] = True
		out = ''
		while z >= 0 and arr[z]:
			out += str(z + 1) + ' '
			z -= 1
		print(out)
main()


n = int(input())
a = [0] * (n + 1)
b = list(map(int, input().split()))
i = 0
p = n
while n and i < p:
	if n == b[i]:
		a[b[i]] = 1
		while a[n] != 0:
			print(n, end=' ')
			n -= 1
		print()
		i = i + 1
	else:
		print()
		a[b[i]] = 1
		i += 1


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('')


n = input()
n = int(n)
a = [int(v) for v in input().split()]
done = set()
i = n
for v in a:
	done.add(v)
	while i >= 1:
		if i in done:
			print(i, end=' ')
			i -= 1
		else:
			print()
			break


x = int(input())
l = list(map(int, input().split()))
mat = list(range(1, x + 1))[::-1]
le = x
op = set()
s = ''
for i in l:
	op.add(i)
	while le in op:
		s += str(le) + ' '
		le -= 1
	s += '\n'
print(s)


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())
snacks = list(map(int, input().split(' ')))
stack = n
available = []
for i in range(0, n + 1):
	available.append(0)
for i in range(0, n):
	available[snacks[i] - 1] = 1
	while available[stack - 1] != 0 & stack >= 0:
		print(stack, end=' ')
		stack -= 1
	print('')


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = 1
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
arr = zzz()
ans = [0] * (n + 1)
x = n
for i in range(n):
	ans[arr[i]] = 1
	while ans[x] == 1:
		print(x, end=' ')
		x -= 1
	print()


upper = n = int(input())
cur = set()
enter = map(int, input().split())
for x in enter:
	cur.add(x)
	while upper in cur:
		print(upper, end=' ')
		upper -= 1
	print()


from sys import stdin, stdout
from collections import defaultdict
import heapq

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()
INF = 10000000000.0

class MaxHeap:

	def __init__(self):
		self.data = []

	def top(self):
		return -self.data[0]

	def push(self, val):
		heapq.heappush(self.data, -val)

	def pop(self):
		return -heapq.heappop(self.data)

	def isempty(self):
		if len(self.data) != 0:
			return True
		return False
n = get_int()
ar = get_array()
st = MaxHeap()
maxh = n
for i in ar:
	st.push(i)
	if st.top() == maxh:
		while st.isempty() == True and st.top() == maxh:
			print(st.pop(), end=' ')
			maxh -= 1
		print()
	else:
		print()


n = int(input(''))
x = n
y = [int(x) for x in input('').split()]
a = [0] * (n + 1)
for i in range(n):
	el = y[i]
	a[el] = 1
	s = ''
	while a[x] == 1:
		s += str(x) + ' '
		x -= 1
	print(s)


n = int(input())
a = [(int(x), i + 1) for (i, x) in enumerate(input().split())]
a.sort(key=lambda x: -x[0])
k = 1
s = []
for i in range(n):
	mk = a[i][1]
	while mk > k:
		print()
		k += 1
	print(a[i][0], end=' ')


n = int(input())
l = [int(x) for x in input().split()]
d = set()
for i in l:
	d.add(i)
	while n in d:
		print(n, end=' ')
		n -= 1
	print()


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()


n = int(input())
a = list(map(int, input().split()))
j = n
q = [0 for i in range(n + 1)]
for i in range(n):
	q[a[i]] = 1
	if q[j] == 1:
		while True:
			if q[j] != 1:
				break
			print(j, end=' ')
			q[j] = 0
			j = j - 1
	print()


n = int(input())
next = n
snacks = {}
for i in list(map(int, input().split())):
	snacks[i] = False
for i in snacks.keys():
	snacks[i] = True
	while next != 0 and snacks[next] == True:
		print(next, end=' ')
		next -= 1
	print('')


n = int(input())
snacks = [int(i) for i in input().split()]
pos = n - 1
maior = n
pulou = True
controle = [0] * n

def verifica():
	global pulou
	global pos
	for j in range(pos, -1, -1):
		if controle[j] == 1:
			print(j + 1, end=' ')
			pos -= 1
		else:
			if not pulou:
				print()
				print()
				pulou = True
			else:
				print()
			return
for i in range(len(snacks)):
	controle[snacks[i] - 1] = 1
	verifica()
print()


n = int(input())
a = list(map(int, input().split(' ')))
fallen = {'foo', 'bar'}
next = n
for i in a:
	fallen.add(i)
	if i != next:
		print()
	else:
		print(i, end=' ')
		next -= 1
		for j in range(len(fallen)):
			if next in fallen:
				print(next, end=' ')
				next -= 1
			else:
				break
		print()


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


import sys
n = int(input())
r = [int(i) for i in input().split()]
a = [0] * (n + 1)
j = n
for i in r:
	a[i] = 1
	while a[j] == 1:
		sys.stdout.write(str(j) + ' ')
		j = j - 1
	print()


n = int(input())
s = list(map(int, input().split()))
e1 = []
e2 = set()
f = '\n'
r = ''
for i in s:
	e2.add(i)
	while n in e2:
		print(n, end=' ')
		n -= 1
	print()


n = int(input())
x = n
ls = list(map(int, input().split()))
ls.insert(0, 0)
arr = [None] * 100005
for i in range(1, n + 1):
	arr[ls[i]] = 1
	while arr[x] and x != 0:
		print(x, end=' ')
		x -= 1
	print()


n = int(input())
li = list(map(int, input().split(' ')))
check = []
for x in range(n):
	check.append(False)
i = n
for x in li:
	check[x - 1] = True
	while i > 0 and check[i - 1] == True:
		print(i, end=' ')
		i -= 1
	print()


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