# https://codeforces.com/problemset/problem/767/A

n = int(input())
stack = list()
snack = tuple(map(int, input().split()))
for i in range(n):
    if not stack:
        stack.append(snack[i])
    else:
        if snack[i] > stack[-1]:
            stack.append(snack[i])
            print()
        else:
            print(*stack[::-1])
            stack = [snack[i]]

print(*stack[::-1])

4fe36b7b99e33cfb698a5f48cacc4e3a6f825363
<mask token>

<mask token>
for i in range(n):
    if not stack:
        stack.append(snack[i])
    elif snack[i] > stack[-1]:
        stack.append(snack[i])
        print()
    else:
        print(*stack[::-1])
        stack = [snack[i]]
print(*stack[::-1])

n = int(input())
stack = list()
snack = tuple(map(int, input().split()))
for i in range(n):
    if not stack:
        stack.append(snack[i])
    elif snack[i] > stack[-1]:
        stack.append(snack[i])
        print()
    else:
        print(*stack[::-1])
        stack = [snack[i]]
print(*stack[::-1])

# https://codeforces.com/problemset/problem/767/A

n = int(input())
stack = list()
snack = tuple(map(int, input().split()))
for i in range(n):
    if not stack:
        stack.append(snack[i])
    else:
        if snack[i] > stack[-1]:
            stack.append(snack[i])
            print()
        else:
            print(*stack[::-1])
            stack = [snack[i]]

print(*stack[::-1])
