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.

Source: codeforces | Difficulty: EASY
Tags: Data structures

Implementation


Solutions:
n = int(input())
arr = list(map(int, input().split()))
inds = [0] * n
for i in range(n):
	inds[arr[i] - 1] = i
top = n - 1
for i in range(n):
	op = []
	while inds[top] <= i:
		op += [str(top + 1)]
		top -= 1
		if top == -1:
			break
	print(' '.join(op))


N = int(input())
Arr = [int(_) for _ in input().split()]
dic = {}
for i in range(N):
	dic[Arr[i]] = i
curr_i = -1
main_index = 0
for j in range(N, 0, -1):
	k = dic[j]
	if k > curr_i:
		curr_i = k
		print('\n' * (k - main_index), end='')
		print(j, end=' ')
		main_index = k
	elif k < curr_i:
		print(j, end=' ')


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


import sys
n = int(input())
l = list(map(int, input().split()))
d = {}
elem = n
for i in l:
	d[i] = 1
	try:
		while True:
			k = d[elem]
			print(elem, end=' ')
			elem -= 1
	except KeyError:
		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())
l = map(int, input().split())
s = set()
for i in l:
	s.add(i)
	while n in s:
		print(n, end=' ')
		n -= 1
	print()


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


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


from sys import stdin
from sys import stdout
w = stdout.write
w = stdout.write
inp = stdin.readline
n = int(inp())
a = [0 for i in range(n + 1)]
st = [n + 1]
s = list(map(int, inp().split()))
t = 1
i = 0
top = 0
while i < n:
	ans = []
	temp = st[top]
	if temp == s[i] + 1:
		ans.append(str(s[i]))
		st.append(s[i])
		t = t + 1
		top = top + 1
		while a[temp - 2] == 1:
			a[temp - 2] = 0
			st.append(temp - 2)
			t = t + 1
			ans.append(str(temp - 2))
			temp = temp - 1
			top = top + 1
	else:
		a[s[i]] = 1
	i = i + 1
	w(' '.join(ans))
	w('\n')


import sys
from math import sqrt
input = lambda : sys.stdin.readline()

def Main():
	a = int(input())
	sn = input().split(' ')
	c = a
	s = set()
	for i in range(a):
		if int(sn[i]) == c:
			r = []
			r.append(c)
			for j in range(c - 1, 0, -1):
				if j in s:
					r.append(j)
					c = j
				else:
					break
			c = c - 1
			print(' '.join(map(str, r)))
		else:
			s.add(int(sn[i]))
			print('')
Main()


N = int(input())
Candies = [int(x) for x in input().split()]
FallenCandies = [False] * N
C = N
for i in range(N):
	FallenCandies[Candies[i] - 1] = True
	while FallenCandies[C - 1] == True and C > 0:
		C -= 1
		print(C + 1, end=' ')
	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())
arr = [int(i) for i in input().split()]
b = [0 for i in range(n + 1)]
for i in range(n):
	b[arr[i]] = 1
	line = []
	while b[n]:
		line.append(str(n))
		n -= 1
	print(' '.join(line))


n = int(input())
s = list(map(int, input().split()))
stack = [False] * n
last = n - 1
for i in range(n):
	stack[s[i] - 1] = True
	while last >= 0 and stack[last]:
		print(last + 1, end=' ')
		last -= 1
	print()


(n, s) = (int(input()), set())
for a in map(int, input().split()):
	c = []
	s.add(a)
	while n in s:
		c.append(n)
		n -= 1
	print(*c)


n = int(input())
k = n
snacks = [int(x) for x in input().split()]
pastsnacks = (n + 1) * [0]
for i in range(n):
	pastsnacks[snacks[i]] = 1
	if snacks[i] != k:
		print()
	elif snacks[i] == k:
		print(k, end='')
		k -= 1
		while pastsnacks[k] == 1:
			print(' ', k, end='')
			k -= 1
		if i != n:
			print()


n = int(input())
l = list(map(int, input().split()))
s = set()
for d in l:
	s.add(d)
	if n in s:
		print(f'{n}', end=' ')
		n -= 1
		while n in s:
			print(n, end=' ')
			n -= 1
		print()
	else:
		print()


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input().strip()
n = I()
a = li()
k = n
d = deque([])
i = 0
b = [0] * n
j = n - 1
for i in range(0, n):
	b[a[i] - 1] = 1
	while j >= 0 and b[j]:
		print(j + 1, end=' ')
		j -= 1
	print()


n = int(input())
li = list(map(int, input().split()))
col = [0 for i in range(n + 2)]
t = n
for i in range(n):
	col[li[i]] += 1
	while col[t]:
		print(t, end=' ')
		t -= 1
	print('')


n = int(input())
coming = list(map(int, input().split(' ')))
(nxt, inHand) = (n, [0] * n)
for i in coming:
	inHand[i - 1] = 1
	while inHand[nxt - 1]:
		print(nxt, end=' ')
		inHand[nxt - 1] = 0
		nxt -= 1
	print()


n = int(input())
arr = list(map(int, input().split()))
found = [0 for x in range(n + 1)]
nextOne = n
for x in arr:
	found[x] = 1
	output = []
	while nextOne > 0 and found[nextOne] == 1:
		output.append(str(nextOne))
		nextOne -= 1
	print(' '.join(output))


n = int(input())
t = []
for i in range(n + 1):
	t.append(0)
num = input().split()
for i in range(n):
	num[i] = int(num[i])
nextnum = n
for i in range(n):
	t[num[i]] = 1
	while t[nextnum] == 1:
		print(nextnum, ' ', end='')
		nextnum -= 1
	print('')


from sys import stdin
n = int(input())
a = []
line = input()
a.extend([int(x) for x in line.split()])
q = n
l = n
r = n
i = 0
ans = []
d = dict()
while i < n:
	if a[i] == q:
		j = q
		d[q] = True
		while j in d:
			j -= 1
		q = j
		ans.append([a[i], j])
	elif a[i] < q:
		ans.append([])
		d[a[i]] = True
	i += 1
for p in ans:
	if not p:
		print('')
	else:
		for i in range(p[0], p[1], -1):
			print(i, end=' ')
		print('')


import heapq
n = int(input())
snacks = list(map(int, input().split()))
heap = []
heapq.heapify(heap)
for e in snacks:
	if e == n:
		ans = []
		ans.append(n)
		while heap:
			if abs(heap[0]) == n - 1:
				ans.append(abs(heapq.heappop(heap)))
				n = n - 1
			else:
				break
		print(*ans)
		n = n - 1
	else:
		print('')
		heapq.heappush(heap, -e)


n = int(input())
l = list(map(int, input().split()))
has = set()
nex = n
for i in range(n):
	has |= {l[i]}
	ans = []
	while nex in has:
		ans += [nex]
		nex -= 1
	print(*ans)


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())
available = set()
for current in map(int, input().split()):
	currentLineSol = []
	available.add(current)
	while n in available:
		currentLineSol.append(n)
		n -= 1
	print(*currentLineSol)


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


n = int(input())
s = [int(x) for x in input().split()]
order = {}
for i in range(len(s)):
	order[s[i]] = i
if order[n] != 0:
	print('\n' * (order[n] - 1))
last = n
for i in range(n - 1):
	if order[n - i] == n:
		for x in range(i, n - 1):
			print(n - i, end=' ')
		break
	elif order[n - i - 1] > order[last]:
		print(n - i, '', end='\n' * (order[n - i - 1] - order[last]))
		last = n - i - 1
	else:
		print(n - i, end=' ')
print('1')


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


n = int(input())
arr = [int(inp) for inp in input().split()]
num = n
present = dict()
for i in arr:
	present[i] = True
	while num in present:
		print(num, end=' ')
		num -= 1
	print('')


from sys import stdin, stdout, maxsize
tup = lambda : map(int, stdin.readline().split())
I = lambda : int(stdin.readline())
lint = lambda : [int(x) for x in stdin.readline().split()]
stpr = lambda x: stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
n = I()
ls = lint()
arr = [0] * (n + 2)
for i in ls:
	arr[i] = 1
	while arr[n]:
		print(n, end=' ')
		n -= 1
	print()


n = int(input())
vis = set()
a = map(int, input().split())
cur = n
for x in a:
	vis.add(x)
	while cur in vis:
		print(cur, end=' ')
		cur -= 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())
numbers = map(int, input().split())
found = [False] * (n + 1)
maxn = n
for m in numbers:
	found[m] = True
	out = ''
	if m == maxn:
		while found[m]:
			out += str(m) + ' '
			m -= 1
		maxn = m
	print(out[:-1])


n = int(input())
s = list(map(int, input().split()))
fallen_sneks = [None] * 100000
for snek in s:
	if snek != n:
		fallen_sneks[snek - 1] = snek
		print()
	else:
		fallen_sneks[n - 1] = snek
		stak = ''
		while fallen_sneks[n - 1] != None and n > 0:
			stak += str(n) + ' '
			n -= 1
		print(stak.strip())


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


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


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


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())
a = list(map(int, input().split()))
ordered_a = sorted([(i, idx) for (idx, i) in enumerate(a)], reverse=True)
res = [[] for _ in range(len(a))]
last_idx = -1
for (size, idx) in ordered_a:
	if last_idx < idx:
		res[idx].append(size)
		last_idx = idx
	else:
		res[last_idx].append(size)
for r in res:
	if len(r) > 0:
		print(' '.join((str(i) for i in r)))
	else:
		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()


(n, ss) = (int(input()), input().split())
(k, res, idx) = (n, [''] * n, [False] * (n + 1))
for (i, j) in enumerate(list(map(int, ss))):
	idx[j] = ss[i]
	if idx[k]:
		tmp = []
		while idx[k]:
			tmp.append(idx[k])
			k -= 1
		res[i] = ' '.join(tmp)
print('\n'.join(res))


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)


from sys import stdin
lines = stdin.readlines()
n = int(lines[0])
marked = n * [False]

def mark(num):
	marked[num - 1] = True

def get_consecutively_marked(cur_number):
	result = []
	while cur_number >= 1 and is_marked(cur_number):
		result.append(cur_number)
		cur_number -= 1
	return result

def print_sequence(sequence):
	print(' '.join(map(str, sequence)))

def is_marked(num):
	return marked[num - 1]

def next_line():
	print()
sequence = map(int, lines[1].split())
next_to_print = n
for num in sequence:
	mark(num)
	marked_sequence = get_consecutively_marked(next_to_print)
	print_sequence(marked_sequence)
	next_to_print -= len(marked_sequence)


n = int(input())
snacks = list(map(int, input().split()))
indices = [-1 for i in range(n)]
big = n
index = n - 2
for i in range(n):
	if snacks[i] == big:
		indices[snacks[i] - 1] = 0
		output = str(big)
		j = index
		while indices[j] != -1 and j > -1:
			output += ' ' + str(j + 1)
			j -= 1
		index = j - 1
		big = j + 1
		print(output)
	else:
		print(' ')
		indices[snacks[i] - 1] = 0


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())
arr = list(map(int, input().split()))
b = [False] * n
max_curr = n
for a in arr:
	if a == max_curr:
		max_curr -= 1
		s = str(a)
		while b[max_curr - 1] and max_curr > 0:
			b[max_curr - 1] = False
			s += ' ' + str(max_curr)
			max_curr -= 1
		print(s)
	else:
		print('')
		b[a - 1] = True


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


def main():
	n = int(input())
	sizes = [int(c) for c in input().split()]
	sizes2 = sorted([(e, i) for (i, e) in enumerate(sizes)], reverse=True)
	lines = [[] for _ in range(n)]
	i = 0
	while i < n:
		(k, v) = sizes2[i]
		lines[v].append(k)
		i += 1
		while i < n and sizes2[i][1] < v:
			lines[v].append(sizes2[i][0])
			i += 1
	for line in lines:
		print(*line)
main()


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())
snack_sizes = [int(c) for c in input().split(' ')]
felt_snack_list = [0] * n
waiting_for = n
for snack in snack_sizes:
	i = snack - 1
	felt_snack_list[i] = snack
	if snack == waiting_for:
		j = i
		tower_built = []
		while j >= 0 and felt_snack_list[j]:
			tower_built.append(felt_snack_list[j])
			j -= 1
		print(*tower_built)
		waiting_for = j + 1
	else:
		print()


from queue import PriorityQueue

def get_na_fila(show_snack, maior):
	while True:
		if fila_preferencia.empty():
			break
		snack = -1 * fila_preferencia.get()
		if snack == maior:
			show_snack.append(snack)
			maior -= 1
		else:
			fila_preferencia.put(-1 * snack)
			break
	return maior
maior = int(input())
snacks = map(int, input().split())
(fila_preferencia, show_snack) = (PriorityQueue(), list())
for snack in snacks:
	if snack == maior:
		show_snack.append(snack)
		maior -= 1
		maior = get_na_fila(show_snack, maior)
		print(*show_snack)
		show_snack = list()
	else:
		fila_preferencia.put(-1 * snack)
		print()


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


n = int(input())
arv = [0] * (n + 1)
arr = [int(x) for x in input().split()]
arr.insert(0, 0)
arv[arr[0]] = 1
m = n
for q in range(1, n + 1):
	arv[arr[q]] = 1
	while arv[m] and m > 0:
		print(m, end=' ')
		m -= 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()


n = int(input())
string = input()
order = list(map(int, string.split()))
snacks = [0 for x in range(n)]
c = n - 1
for x in order:
	snacks[x - 1] = 1
	day = []
	for y in range(c, -1, -1):
		if snacks[y] == 0:
			break
		day.append(y + 1)
		c -= 1
	print(' '.join(map(str, day)))


ln = int(input())
fel = list(map(int, input().split(' ')))
mx = ln
stor = set()
pnt = ''
for i in range(ln):
	if fel[i] < mx:
		stor.add(fel[i])
		print('')
	elif fel[i] == mx:
		pnt += str(fel[i])
		for j in range(fel[i] - 1, 0, -1):
			if j in stor:
				pnt += ' ' + str(j)
			else:
				mx = j
				break
		print(pnt)
		pnt = ''


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


def placeSnacks(n, snacks):
	availableSnacks = [None] * n
	for snack in snacks:
		availableSnacks[int(snack) - 1] = snack
		while availableSnacks[n - 1] and n != 0:
			print('{n}'.format(n=n), end=' ')
			n -= 1
		print('')
n = int(input().strip())
snacks = input().strip().split()
placeSnacks(n, snacks)


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 = int(input())
snacks = 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())
a = list(map(int, input().split()))
t = [False] * n
t_idx = n - 1
for (idx, value) in enumerate(a):
	t[value - 1] = True
	cur_res = []
	while t[t_idx]:
		cur_res.append(t_idx + 1)
		t_idx -= 1
		if t_idx == -1:
			break
	print(*cur_res)


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())
t = [0] * n
n = list(map(int, input().split()))
l_s = list()
i = 0
while len(t) != 0:
	t[n[i] - 1] = 1
	a = list()
	while len(t) != 0 and t[len(t) - 1] == 1:
		a.append(len(t))
		del t[len(t) - 1]
	print(' '.join((str(x) for x in a)))
	i += 1


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


from collections import deque as d
n = int(input())
a = list(map(int, input().split()))
s = set()
cur = d()
left = d(sorted(a))
for i in range(n):
	cur.append(a[i])
	s.add(a[i])
	if left and left[-1] in s:
		t = d()
		while left and left[-1] in s:
			s.remove(left[-1])
			t.append(left.pop())
		print(*t)
	else:
		print()


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


import sys

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()]
	app_n = [0] * (n + 1)
	for (i, a) in enumerate(A):
		app_n[a] = i
	nxt = n
	for i in range(n):
		tmp = []
		while nxt > 0 and app_n[nxt] <= i:
			tmp.append(nxt)
			nxt -= 1
		print(*tmp)
solve()


n = int(input())
nums = list(map(int, input().split(' ')))
used = [False] * (n + 1)
next_val = n
for num in nums:
	used[num] = True
	if num == next_val:
		i = num
		to_print = [str(i)]
		while used[i - 1]:
			i -= 1
			to_print.append(str(i))
		next_val = i - 1
		print(' '.join(to_print))
	else:
		print()


from sys import stdin
n = int(stdin.readline())
s = list(map(int, stdin.readline().split()))
idx = [False] * (n + 1)
res = [''] * n
k = n
for i in range(n):
	x = s[i]
	idx[x] = x
	if k == x:
		temp = []
		while idx[k]:
			temp.append(idx[k])
			k -= 1
		res[i] = ' '.join([str(a) for a in temp])
print('\n'.join(res))


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


def find_smaller_continiusly(size, lst):
	print(size, end='')
	while size > 1:
		size -= 1
		if lst[size - 1] == 1:
			print(' {}'.format(size), end='')
		else:
			break
	print()
	return size
max_size = int(input())
snacks = [int(x) for x in input().split(' ')]
already_fallen = [0] * max_size
for snack in snacks:
	if snack == max_size:
		max_size = find_smaller_continiusly(max_size, already_fallen)
	else:
		already_fallen[snack - 1] = 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()


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


a = int(input())
b = list(map(int, input().split()))
vis = [0] * (a + 1)
c = a
for i in range(len(b)):
	vis[b[i]] = True
	while vis[c] and c > 0:
		print(c, end=' ')
		c -= 1
	if i != len(b) - 1:
		print()


n = int(input())
arr = list(map(int, input().split()))
listt = [0] * n
next = 0
expected = n
for i in range(len(arr)):
	flag = 0
	listt[n - arr[i]] = arr[i]
	if listt[next] == expected:
		prevnext = next
		for j in range(prevnext, n):
			if listt[j] == 0:
				flag = 1
				next = j
				break
		if flag == 0:
			print(*listt[prevnext:])
		else:
			print(*listt[prevnext:next])
		expected = listt[next - 1] - 1
	else:
		print()


n = int(input())
curr = n
arr = list(map(int, input().split(' ')))
table = [False] * (n + 1)
for i in range(n):
	table[arr[i]] = True
	if table[curr]:
		while table[curr]:
			print(curr, end=' ')
			curr -= 1
		print()
	else:
		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()


from sys import stdin, stdout
import math
from fractions import gcd

def sin():
	return stdin.readline().rstrip()

def listInput():
	return list(map(int, sin().split()))

def printBS(li):
	if not li:
		return
	for i in range(len(li) - 1):
		stdout.write('%d ' % li[i])
	stdout.write('%d\n' % li[-1])
n = int(sin())
li = listInput()
temp = [(li[i], i) for i in range(n)]
temp.sort(reverse=True)
ans = [[] for _ in range(n)]
ans[temp[0][1]].append(temp[0][0])
prev = temp[0][1]
for i in range(1, n):
	(a, b) = temp[i]
	if b < prev:
		ans[prev].append(a)
	else:
		ans[b].append(a)
		prev = b
for l in ans:
	if len(l) == 0:
		print()
	else:
		printBS(l)


import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def def_value():
	return 0
n = inp()
a = inlist()
mark = [0] * (n + 1)
nxt = n
for i in a:
	mark[i] = 1
	while mark[nxt] == 1:
		print(nxt, end=' ')
		mark[nxt] = 0
		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()


IL = lambda : list(map(int, input().split()))
I = lambda : int(input())
n = I()
a = IL()
fallen = [False for i in range(100001)]
waiting = n
for w in a:
	fallen[w] = True
	if fallen[waiting]:
		prev = waiting
		for i in range(waiting - 1, -1, -1):
			if not fallen[i]:
				waiting = i
				break
		print(' '.join(map(str, range(prev, waiting, -1))))
	else:
		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())
lis = list(map(int, input().split()))
have = set()
for i in lis:
	have.add(i)
	while n in have:
		print(n, end=' ')
		n -= 1
	print()


n = input()
snack_sequence = input().split(' ')
snack_list = [False] * int(n)
next_largest_snack = int(n)
for snack in snack_sequence:
	current_snack = int(snack)
	snack_list[current_snack - 1] = True
	if int(snack) == next_largest_snack:
		while current_snack > 0 and snack_list[current_snack - 1]:
			print(current_snack, end='')
			current_snack -= 1
			if current_snack > 0 and snack_list[current_snack - 1]:
				print(' ', end='')
		next_largest_snack = current_snack
		if current_snack > 0:
			print('')
	else:
		print('')


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())
size1 = input().split()
size2 = {}
count = n
for i in size1:
	size2[i] = 1
	if int(i) == count:
		print(count, end='')
		count -= 1
		while str(count) in size2:
			print('', count, end='')
			count -= 1
		print('')
	else:
		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()))
z = set()
for i in a:
	z.add(i)
	while n in z:
		print(n, end=' ')
		n -= 1
	print(' ')


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


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


n = int(input())
lst = [int(i) for i in input().split()]
lst2 = [0] * n
for i in lst:
	lst2[i - 1] = 1
	while n >= 1 and lst2[n - 1] == 1:
		print(n, end=' ')
		n -= 1
	print('')


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())
arr = list(map(int, input().split()))
arr = list(zip(arr, range(n)))
arr.sort(reverse=True)
ans = [[] for _ in range(n)]
cur = -1
for i in range(n):
	cur = max(cur, arr[i][1])
	ans[cur].append(arr[i][0])
for i in range(n):
	print(*ans[i])


from collections import deque

def main():
	n = int(input())
	snack = deque([int(i) for i in input().split()])
	temp = set()
	for _ in range(n, 0, -1):
		i_th_snack = snack.popleft()
		temp.add(i_th_snack)
		if i_th_snack != n:
			print()
		else:
			while temp and n in temp:
				print('{} '.format(n), end='')
				temp.discard(n)
				n -= 1
			print()
main()


n = int(input())
numbers = map(int, input().split())
s = set()
max_val = n
for num in numbers:
	s.add(num)
	out = ''
	while max_val in s:
		out += str(max_val) + ' '
		max_val -= 1
	print(out[:-1])


import sys
import heapq

def main(arr):
	visited = [False] * len(arr)
	last = len(visited) - 1
	for n in arr:
		visited[n - 1] = True
		doing = []
		while last >= 0 and visited[last]:
			doing.append(last + 1)
			last -= 1
		print(' '.join((str(d) for d in doing)))
for (e, line) in enumerate(sys.stdin.readlines()):
	if e == 0:
		continue
	else:
		arr = list(map(int, line.strip().split()))
main(arr)


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().strip())
arr = list(map(int, input().strip().split()))
temp = set()
curr = n
for ele in arr:
	ans = []
	if ele != curr:
		temp.add(ele)
	else:
		ans.append(curr)
		curr -= 1
		while len(temp):
			if curr not in temp:
				break
			ans.append(curr)
			temp.remove(curr)
			curr -= 1
	print(*ans)


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


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


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


import heapq
highest = int(input())
line = input()
line = [int(k) for k in line.split()]
waitingCandy = []
for i in line:
	i = i * -1
	heapq.heappush(waitingCandy, i)
	x = heapq.heappop(waitingCandy)
	heapq.heappush(waitingCandy, x)
	x = x * -1
	while x == highest:
		print(x, end=' ')
		highest -= 1
		heapq.heappop(waitingCandy)
		if waitingCandy:
			x = heapq.heappop(waitingCandy)
			heapq.heappush(waitingCandy, x)
			x = x * -1
		else:
			break
	print('')


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


from operator import itemgetter
n = int(input())
data = sorted(enumerate(map(int, input().split())), key=itemgetter(1))
cur = n
old = -1
while cur > 0:
	i = data[cur - 1][0]
	for k in range(i - old - 1):
		print()
	old = i
	res = []
	while i <= old:
		res.append(cur)
		cur -= 1
		if not cur:
			break
		i = data[cur - 1][0]
	print(*res)


n = int(input())
a = list(map(int, input().split()))
found = [False] * (n + 1)
go_back = n
for i in a:
	found[i] = True
	if i == go_back:
		bucket = []
		while found[i]:
			bucket.append(i)
			i -= 1
		print(' '.join([str(item) for item in bucket]))
		if i > 0:
			go_back = i
	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()


def imprime_vetor(vetor):
	l = len(vetor)
	if l > 0:
		print(vetor[0], end='')
		for i in range(1, l):
			print(' ', vetor[i], end='')

def novo_maximo(marcadores, n):
	global atual
	vetor = []
	for i in range(atual - 1, -1, -1):
		if marcadores[i] == True:
			vetor.append(i + 1)
		else:
			atual = i + 1
			return vetor
	atual = i + 1
	return vetor
n = int(input())
tamanhos = input().split(' ')
tamanhos = [int(x) for x in tamanhos]
marcadores = [False] * n
proximos = []
atual = n
for i in tamanhos:
	marcadores[i - 1] = True
	proximos.append(i)
	if i == atual:
		imprime_vetor(novo_maximo(marcadores, n))
	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()


import math

def fact(n):
	ans = 1
	for i in range(2, n + 1):
		ans *= i
	return ans

def comb(n, c):
	return fact(n) // (fact(n - c) * c)
n = int(input())
d = list(map(int, input().split()))
has = [0 for i in range(n + 1)]
has[0] = 0
nxt = n
ans = []
for i in range(n):
	if d[i] == nxt:
		temp = [str(nxt)]
		nxt -= 1
		while has[nxt]:
			temp.append(str(nxt))
			has[nxt] = 0
			nxt -= 1
		ans.append(temp)
	else:
		has[d[i]] = 1
		ans.append([''])
for i in range(n):
	print(' '.join(ans[i]))


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


a = int(input())
(b, c) = ([int(x) for x in input().split(' ')], set())
for x in b:
	if not x == a:
		c.add(x)
		print(' ', end='\n')
	else:
		res = str(x)
		while True:
			a -= 1
			if a in c:
				res += ' ' + str(a)
			else:
				break
		print(res, end='\n')


n = int(input())
snacks = list(map(int, input().split()))
needed = n
current = [0] * n
for i in range(n):
	if snacks[i] != needed:
		current[snacks[i]] = 1
		print('')
	elif needed > 0:
		this_day = [str(needed)]
		needed -= 1
		while True:
			if current[needed]:
				this_day.append(str(needed))
				needed -= 1
			else:
				break
		print(' '.join(this_day))


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


import sys
input = sys.stdin.readline
import math

def inpit():
	return int(input())

def inplt():
	return list(map(int, input().split()))

def inpstr():
	s = input()
	return list(s[:len(s) - 1])

def inpspit():
	return map(int, input().split())
import math

def lcm(a):
	return abs(math.prod(a)) // math.gcd(*a)
n = inpit()
l = inplt()
st = [i for i in range(1, n + 1)]
hold = {}
ans = []
for i in l:
	if i == st[-1]:
		ans.append(i)
		st.pop()
		if len(st) > 0:
			while st[-1] in hold:
				ans.append(st.pop())
				if len(st) < 1:
					break
		print(*ans)
		ans = []
	else:
		hold[i] = i
		print()


n = int(input())
a = list(map(int, input().split()))
p = sorted(a)
p.reverse()
d = {}
for i in a:
	d[i] = 0
max_so_far = p[0]
for i in range(len(a)):
	if a[i] == max_so_far:
		d[a[i]] += 1
		for j in range(max_so_far, 0, -1):
			if d[j] == 1:
				print(j, end=' ')
				max_so_far = j - 1
			else:
				break
		print('')
	else:
		d[a[i]] += 1
		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())
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())
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()


import sys
import heapq

def main(arr):
	s = sorted(arr, reverse=True)
	max_heap = []
	i = 0
	for (e, num) in enumerate(arr):
		if num == s[i]:
			doing = [num]
			i += 1
			while max_heap and -max_heap[0] == s[i]:
				n = heapq.heappop(max_heap)
				doing.append(-n)
				i += 1
			print(' '.join((str(d) for d in doing)))
		else:
			print()
			heapq.heappush(max_heap, -num)
for (e, line) in enumerate(sys.stdin.readlines()):
	if e == 0:
		continue
	else:
		arr = list(map(int, line.strip().split()))
main(arr)


from collections import deque, defaultdict
num_snacks = int(input())
snacks = deque([int(num) for num in input().split(' ')])
other_sizes = defaultdict(bool)
while snacks:
	sizes_to_print = []
	if snacks:
		current_size = snacks.popleft()
	if current_size == num_snacks:
		num_snacks -= 1
		sizes_to_print.append(current_size)
		while other_sizes[num_snacks]:
			if other_sizes[num_snacks] == True:
				sizes_to_print.append(num_snacks)
				num_snacks -= 1
				continue
		print(*sizes_to_print)
		continue
	other_sizes[current_size] = True
	print()


n = int(input())
l = [int(i) for i in input().split()]
b = n * [0]
c = n
for i in range(n):
	if l[i] == c:
		ch = str(c)
		c = c - 1
		while b[c - 1] != 0:
			ch += ' ' + str(c)
			c = c - 1
		print(ch)
	else:
		b[l[i] - 1] = l[i]
		print('')


qtd = int(input())
lista = list(map(int, input().split()))
cairam = set()
prox = qtd
for i in range(qtd):
	foram = []
	cairam.add(lista[i])
	while prox in cairam:
		foram.append(prox)
		prox -= 1
	print(*foram)


n = int(input())
snacks = [int(x) for x in input().split()]
aux = [-1 for num in range(n + 1)]
curSnack = n
for i in range(len(snacks)):
	aux[snacks[i]] = 1
	if snacks[i] == curSnack:
		out = str(curSnack)
		j = curSnack - 1
		while aux[j] != -1:
			out += ' %d' % j
			j = j - 1
		print(out)
		curSnack = j
	else:
		aux[snacks[i]] = 1
		print()


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


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())
a = [i for (i, j) in sorted(list(enumerate(map(int, input().split()))), key=lambda x: x[-1])]
b = [list([]) for i in range(n)]
mx = a[-1]
for i in range(n - 1, -1, -1):
	if a[i] > mx:
		mx = a[i]
	b[mx].append(i + 1)
for i in b:
	print(*i)


import heapq
n = int(input())
snacks = list(map(int, input().split(' ')))
max_snack_size = max(snacks)
snack_stock = []
snack_missed = []
for i in range(len(snacks)):
	if max_snack_size == snacks[i]:
		snack_stock.append([snacks[i]])
		if snack_missed:
			top_of_snack_missed = -1 * snack_missed[0]
			while top_of_snack_missed + 1 == max_snack_size:
				snack_stock[-1].append(-1 * heapq.heappop(snack_missed))
				if snack_missed:
					top_of_snack_missed = -1 * snack_missed[0]
				max_snack_size -= 1
		max_snack_size -= 1
	else:
		snack_stock.append([])
		heapq.heappush(snack_missed, -1 * snacks[i])
for i in snack_stock:
	if not i:
		print('')
	else:
		print(' '.join(map(str, i)))


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


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

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

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

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

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

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
n = iinp()
arr = lmp()
x = n
tmp = []
fell = l1d(n + 1)
for i in range(n):
	fell[arr[i]] = 1
	while fell[x]:
		tmp.append(x)
		x -= 1
	if len(tmp):
		print(*tmp)
		tmp = []
	else:
		print()


n = int(input())
arr = list(map(int, input().split()))
f_arr = [0] * (n + 1)
maxx = n
result = []
for i in range(n):
	f_arr[arr[i]] += 1
	while f_arr[maxx] == 1:
		result.append(maxx)
		maxx -= 1
	print(*result, sep=' ')
	result.clear()


n = int(input())
snacks = input()
snacks = snacks.split(' ')
snacks = [int(x) for x in snacks]
maxsnack = n
someset = {}
for snack in snacks:
	someset[snack] = 0
for snack in snacks:
	if maxsnack == 0:
		break
	if snack == maxsnack:
		print(maxsnack, end='')
		maxsnack -= 1
		if maxsnack == 0:
			break
		while someset[maxsnack] == 1:
			print(' ', maxsnack, end='')
			someset[snack] = 0
			maxsnack -= 1
			if maxsnack == 0:
				break
		print()
	else:
		someset[snack] = 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()


n = int(input())
sol = set()
for elem in list(map(int, input().split())):
	c = []
	sol.add(elem)
	while n in sol:
		c.append(n)
		n -= 1
	print(*c)


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


n = int(input())
next = n
snacks = [False] * (n + 2)
orderedSnacks = [0] * (n + 2)
orderedSnacks = list(input().split(' '))
for i in range(0, n):
	orderedSnacks[i] = int(orderedSnacks[i])
for i in range(1, n + 1):
	inSnack = orderedSnacks[i - 1]
	snacks[inSnack] = True
	if inSnack == next:
		snacks[next] = False
		print(next, ' ', sep='', end='')
		next = next - 1
		for next in range(next, 0, -1):
			if snacks[next] == True:
				print(next, ' ', end='')
				next = next - 1
			else:
				break
	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 = int(input())
arr = list(map(int, input().split()))
arr_sorted = sorted(arr)
arr_sorted.reverse()
(j, i) = (0, 0)
visited = set()
ans = ''
while i < len(arr):
	visited.add(arr[i])
	ans = ''
	while j < len(arr) and arr_sorted[j] in visited:
		ans += str(arr_sorted[j]) + ' '
		j += 1
	if ans == '':
		print()
	else:
		print(ans[0:-1])
	i += 1


(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())
a = list(map(int, input().split()))
k = n
d = {}
for i in range(n):
	s = a[i]
	tmp = []
	if s == k:
		while s == k:
			tmp.append(s)
			k -= 1
			if k in d:
				s = k
		print(*tmp)
	else:
		d[s] = 1
		print()


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


n = int(input())
inp = input().split()
arr = []
d = {}
for i in range(len(inp)):
	arr.append(int(inp[i]))
for i in range(len(arr)):
	d[arr[i]] = 1
	if d.get(n) != None:
		while d.get(n) != None:
			print(n, end=' ')
			n = n - 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


__author__ = 'Ryabchun Vladimir'

class Stack:

	def __init__(self, element=None):
		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):
		self.__stack.append(element)
		self.length += 1

	def pop(self):
		if self.length == 0:
			raise IndexError('Stack is empty')
		else:
			self.length -= 1
			return self.__stack.pop()

	def last(self):
		if self.length == 0:
			raise IndexError('Stack is empty')
		else:
			return self.__stack[-1]

	def __len__(self):
		return self.length

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


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


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


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


n = int(input())
snacks = list(map(int, input().split()))
ss = set()
for el in snacks:
	curr = []
	ss.add(el)
	while n in ss:
		curr.append(n)
		n -= 1
	print(*curr)


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())
nums = list(map(int, input().split()))
visited = [False] * n
index = n - 1
for i in range(n):
	visited[nums[i] - 1] = True
	while visited[index] == True and index >= 0:
		print(index + 1, end=' ')
		index = index - 1
	print(' ')


n = int(input())
a = list(map(int, input().split()))
s = set([])
w = n

def echo():
	global w
	res = []
	i = w
	while i in s:
		res.append(i)
		s.remove(i)
		i -= 1
	w = i
	print(' '.join(map(str, res)))
for i in a:
	s.add(i)
	if i == w:
		echo()
	else:
		print()


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


from collections import defaultdict, Counter
from functools import lru_cache
from heapq import heappush, heappop, heapify
from math import gcd, floor, ceil
from sys import stdin, stdout

def ilist():
	return [int(x) for x in stdin.readline().strip().split(' ')]

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

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

def solve(a):
	n = len(a)
	ex = n
	h = []
	for s in a:
		res = []
		heappush(h, -s)
		while h and ex == -h[0]:
			res.append(str(ex))
			ex -= 1
			_ = heappop(h)
		print(' '.join(res))
n = iint()
a = ilist()
solve(a)


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)


n = int(input())
a = list(map(int, input().split()))
t = n
for i in range(n):
	a[abs(a[i]) - 1] = -1 * a[abs(a[i]) - 1]
	if abs(a[i]) == t:
		print(t, end=' ')
		t = t - 1
		for j in range(t - 1, -1, -1):
			if a[j] < 0:
				print(t, end=' ')
				t = t - 1
			else:
				print()
				break
	else:
		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 = list(map(int, input().split()))
s = set()
last = n
for i in range(n):
	s.add(a[i])
	if a[i] == last:
		cur = list()
		while last in s:
			cur.append(last)
			last = last - 1
		print(' '.join(map(str, cur)))
	else:
		print('')


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


def solve():
	n = int(input())
	waiting_for = n
	stored = set([])
	for i in [int(i) for i in input().split()]:
		if i == waiting_for:
			stored.add(i)
			res = []
			for j in range(i, 0, -1):
				if j in stored:
					res.append(str(j))
				else:
					waiting_for = j
					break
			print(' '.join(res))
		else:
			print('')
			stored.add(i)
solve()


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())
sequencia = input().split(' ')
tamanho = len(sequencia)
empilhado = []
caiu = [0] * (tamanho + 1)
for i in range(tamanho):
	sequencia[i] = int(sequencia[i])
proximo = n
for i in sequencia:
	caiu[i] = 1
	while caiu[proximo] == 1:
		empilhado.append(proximo)
		proximo -= 1
	print(*empilhado, sep=' ')
	empilhado.clear()


n = int(input())
l = list(map(int, input().split()))
res = []
s = set()
top = n
for i in range(n):
	a = l[i]
	if a != top:
		s.add(a)
		print('')
	else:
		res.append(a)
		a -= 1
		while a in s:
			res.append(a)
			s.remove(a)
			a -= 1
		print(' '.join(map(str, res)))
		res.clear()
		top = a


def snacktower(arr, n):
	final = []
	x = []
	visited = [0] * n
	op = n - 1
	for i in range(n):
		visited[arr[i] - 1] = 1
		while visited[op] == 1 and op >= 0:
			print(op + 1, end=' ')
			op -= 1
		print(' ')
n = int(input())
arr = [int(arr) for arr in input().split()]
snacktower(arr, n)


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


def stack_snacks(n, snacks):
	fallen_snacks = set()
	stacked_items = []
	for s in snacks:
		if s != n:
			fallen_snacks.add(s)
			print('')
		else:
			fallen_snacks.add(s)
			while n in fallen_snacks:
				stacked_items.append(n)
				n -= 1
			print(*stacked_items)
			stacked_items = []
n = int(input())
snacks = list(map(int, input().split()))
stack_snacks(n, snacks)


def main():
	(n, ss) = (int(input()), input().split())
	dd = list(map(int, ss))
	aa = sorted(range(n), key=dd.__getitem__, reverse=True)
	(k, res, idx) = (0, [''] * n, [False] * (n + 1))
	for (i, j) in enumerate(sorted(range(n), key=aa.__getitem__)):
		idx[j] = ss[aa[j]]
		if idx[k]:
			tmp = []
			while idx[k]:
				tmp.append(idx[k])
				k += 1
			res[i] = ' '.join(tmp)
	print('\n'.join(res))
main()


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


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	a = LI()
	r = []
	t = n
	s = set()
	for c in a:
		if c != t:
			s.add(c)
			r.append('')
			continue
		u = [c]
		t -= 1
		while t in s:
			u.append(t)
			t -= 1
		r.append(' '.join(map(str, u)))
	return '\n'.join(r)
print(main())


n = int(input())
snacks = map(int, input().split())
mem = {}
for x in snacks:
	ans = []
	if x == n:
		ans.append(x)
		x -= 1
		while mem.get(x, -1) != -1:
			ans.append(mem[x])
			x -= 1
			n -= 1
		n -= 1
	else:
		mem[x] = x
	print(' '.join(map(str, ans)))


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


n = int(input())
arr = list(map(int, input().split()))
snack = [0] * (n + 1)
cr = n
m = n + 1
op = []
for i in range(n):
	snack[arr[i]] = 1
	if arr[i] == cr:
		while snack[cr] == 1:
			op.append(cr)
			snack[cr] = 2
			cr -= 1
	print(*op)
	op.clear()