Rar the Cat has arranged a row of N bricks. The ith brick from the left has height Ai.
Peanut comes along and attempts to stack these bricks. Going from the leftmost brick to the rightmost, he stacks bricks using the following rules:
By doing so, Peanut will get a stack of bricks with increasing height (top to bottom) at the end of the day. Rar the Cat is curious and wants to know what is in the stack. However, Peanut does not want to let Rar the Cat see the stack. Can you help Rar the Cat find out what is in the stack?
For all testcases, 0 ≤ Ai ≤ 109.
Subtask 1 (23%): 1 ≤ N ≤ 500.
Subtask 2 (28%): 1 ≤ N ≤ 5000.
Subtask 3 (49%): 1 ≤ N ≤ 500000.
Subtask 4 (0%): Sample Testcases.
The first line of input will contain one integer, N.
The second line of input will contain N integers, representing the array A.
The output should contain the heights of the bricks in the stack. The height of the topmost brick should be printed first, one height per line.
10 1 2 9 5 7 6 3 4 2 2
2 4 6 7 9
Brick, i | Height, Ai | Stack (Top -> Bottom) |
---|---|---|
1 | 1 | {1} |
2 | 2 | {2} |
3 | 9 | {9} |
4 | 5 | {5, 9} |
5 | 7 | {7, 9} |
6 | 6 | {6, 7, 9} |
7 | 3 | {3, 6, 7, 9} |
8 | 4 | {4, 6, 7, 9} |
9 | 2 | {2, 4, 6, 7, 9} |
10 | 2 | {2, 4, 6, 7, 9} |
5 5 4 3 2 1
1 2 3 4 5
5 1 2 3 4 5
5
5 4 3 2 1 5
5
Subtask | Score |
---|---|
1 | 23 |
2 | 28 |
3 | 49 |
4 | 0 |