Moving Boxes
1.0s 256MLittle AA is moving house, and he plans to stack the items in his room one by one into a tall, narrow box.
This box is special: only the top is open, so items can only be put in from the top and can only be taken out from the top.
Little AA puts \(N\) items into the box in order: the \(1\)-st item goes at the very bottom, the \(2\)-nd item is stacked on top of it, and so on, with the \(N\)-th item on the very top. Each item has a number printed on it, and the \(i\)-th item put in has number \(a_i\).
After moving to the new house, Little AA takes all the items out of the box. Since he can only take from the top, he first takes out the item that was put in last, and finally the item that was put in first.
Output the sequence of numbers Little AA sees as he takes the items out one by one.
Input
The first line contains a positive integer \(N\), the number of items.
The second line contains \(N\) positive integers \(a_1, a_2, \ldots, a_N\), the numbers of the items in the order Little AA put them into the box.
Constraints
- \(1 \le N \le 100\)
- \(1 \le a_i \le 10^9\)
Output
Output one line containing \(N\) positive integers, the numbers Little AA sees as he takes the items out in order, separated by single spaces.
This problem uses non-strict output comparison. Extra spaces or newlines at the end of a line do not affect the verdict.
Sample Input 1
8
5 8 1 3 9 2 7 4
Sample Output 1
4 7 2 9 3 1 8 5
Sample Input 2
4
10 20 30 40
Sample Output 2
40 30 20 10
Sample Explanation
In the first sample, Little AA puts items numbered \(5, 8, 1, 3, 9, 2, 7, 4\) into the box in order, so the last item \(4\) is on top and the first item \(5\) is at the bottom. Taking them out from the top, the order he sees is \(4, 7, 2, 9, 3, 1, 8, 5\).
Log in to write and submit code. Creating an account is free.