LogiQuest

363. Reverse a Linked List

EasyLinked List

The linked list is given by its values from head to tail. Build it, reverse it in place and print the values from the new head.

Input format

Line 1: n Line 2: n values

Output format

The reversed list.

Example 1

Input

5
1 2 3 4 5

Output

5 4 3 2 1

Example 2

Input

1
7

Output

7

Constraints

1 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…