Reverse Linked List II

MediumLinked List
Next
Linked ListPointer Reversal

Reverse only the portion of a linked list from position left to position right (1-based, inclusive) and leave the rest as it was. Do it in one pass. The values are given as an array; build the linked list from them yourself, then solve it with pointers.

Input

Line 1: n. Line 2: the n node values. Line 3: left and right.

Output

Print the resulting list's values on one line.

Constraints

1 <= left <= right <= n <= 500

Example 1
Input
5
1 2 3 4 5
2 4
Output
1 4 3 2 5

Positions 2 to 4 (2 3 4) become 4 3 2.

Hints

Reverse Linked List II - Medium Linked List Problem | Skill Shiksha