Moving Boxes

1.0s 256M

Little 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\).

Problem page help

Keyboard shortcuts

Main features

  • Sample tests — Runs the sample cases bundled with the problem and auto-compares against the expected output.
  • Custom test — Run your code with your own stdin. Optionally tick the "Compare with expected (diff)" box to verify against expected output line-by-line.
  • Template — Paste the default code template you set on your profile page.
  • Collab — Edit this problem together with classmates in real time.
  • Auto-draft — Editor contents auto-save to your browser every 1.5 seconds (per account / problem / language).
  • Submit — Send your code to the judge for grading; returns AC / WA / TLE etc.

Limits

  • Source code: at most 65,536 characters
  • Custom test stdin and expected output: at most 1 MB each (≈1 million characters)
  • Custom test: about 1 request per 3 s per user (sample test: 1 per 1 s)
  • Custom test has a 15 second wall-clock cap; sample tests use the problem time limit, the same as the official judge
  • Interactive problems do not offer custom test (cannot simulate interaction with the judge).
  • Submitting has no rate limit, but rapid repeated submissions on the same problem are treated as score farming.