#C11296. Reconstruct the Original Sorted List

    ID: 40596 Type: Default 1000ms 256MiB

Reconstruct the Original Sorted List

Reconstruct the Original Sorted List

You are given an array that was originally sorted in ascending order. The array was then rotated to the right by (k) positions. In other words, if the original array is (A = [a_0, a_1, \ldots, a_{n-1}]), then after rotating right by (k) positions, it becomes (B = [a_{n-k}, a_{n-k+1}, \ldots, a_{n-1}, a_0, a_1, \ldots, a_{n-k-1}]). Your task is to restore the original sorted array. The input is provided via standard input (stdin) and the output should be printed to standard output (stdout).

Example: Input: 7 4 5 6 7 1 2 3 4

Output: 1 2 3 4 5 6 7

Note: (k) can range from 0 to (n), where (n) is the number of elements in the array.

inputFormat

The input consists of three lines:

  1. The first line contains an integer (n) representing the number of elements in the array.
  2. The second line contains (n) space-separated integers representing the rotated array.
  3. The third line contains an integer (k) indicating the number of positions by which the array was rotated to the right.

outputFormat

Output the original sorted array as a sequence of space-separated integers on a single line.## sample

7
4 5 6 7 1 2 3
4
1 2 3 4 5 6 7