#### Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

## Problem Description

Rar the Cat has arranged a row of *N* bricks. The *i ^{th}* brick from the left has height

*A*.

_{i}Peanut comes along and attempts to stack these bricks. Going from the leftmost brick to the rightmost, he stacks bricks using the following rules:

- Let the current brick be of height
*X*. - While there is at least 1 brick in the stack, he will remove the topmost brick from the stack if it is smaller than or equals to
*X*. This process is repeated until there is no more bricks in the stack, or the topmost brick is*larger*than*X*. - Add the current brick of height
*X*to the top of the stack.

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?

## Limits

For all testcases, 0 ≤ A_{i} ≤ 10^{9}.

Subtask 1 (23%): 1 ≤ N ≤ 500.

Subtask 2 (28%): 1 ≤ N ≤ 5000.

Subtask 3 (49%): 1 ≤ N ≤ 500000.

Subtask 4 (0%): Sample Testcases.

## Input

The first line of input will contain one integer, *N*.

The second line of input will contain *N* integers, representing the array *A*.

## Output

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.

## Sample Testcase 1

### Input

10 1 2 9 5 7 6 3 4 2 2

### Output

2 4 6 7 9

### Explanation

Brick, i | Height, A_{i} | 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} |

## Sample Testcase 2

### Input

5 5 4 3 2 1

### Output

1 2 3 4 5

## Sample Testcase 3

### Input

5 1 2 3 4 5

### Output

5

## Sample Testcase 4

### Input

5 4 3 2 1 5

### Output

5

### Tags

### Subtasks and Limits

Subtask | Score | #TC | Time | Memory | Scoring |
---|---|---|---|---|---|

1 | 23 | 17 | 1s | 64MB | Minimum |

2 | 28 | 33 | 1s | 64MB | Minimum |

3 | 49 | 51 | 1s | 64MB | Minimum |

4 | 0 | 4 | 1s | 64MB | Minimum |

### Judge Compile Command

g++-7 ans.cpp -o brick -Wall -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512