827. Reverse Linked List

0

Easy

Given the head of a singly linked list, reverse the order of the nodes and return the reversed list.

Input Format

The input consists of an integer N, representing the number of nodes in the linked list. The next line contains N space-separated integers, which are the values of the nodes.

Output Format

Print the reversed linked list, with the values of the nodes separated by a space.

Example

Input

3 1 2 3

Output

3 2 1

Constraints

The number of nodes in the linked list falls within the range of 0 to 5000. Each node's value is an integer between -5000 and 5000.
Loading...

View Submissions

Console