#C7097. Array Rotation: Right Shift

    ID: 50930 Type: Default 1000ms 256MiB

Array Rotation: Right Shift

Array Rotation: Right Shift

You are given an array of integers and an integer \(k\). Your task is to rotate the array to the right by \(k\) steps. This means that each element is shifted to the right by \(k\) positions, and the elements at the end of the array wrap around to the beginning.

For example, if the array is [1, 2, 3, 4, 5, 6] and \(k = 2\), then after rotation the array becomes [5, 6, 1, 2, 3, 4].

The rotation can be achieved by using the reversal algorithm: first reverse the entire array, then reverse the first \(k\) elements, and finally reverse the remaining \(n-k\) elements, where \(n\) is the length of the array.

inputFormat

The input is provided via standard input (stdin) in the following format:

  1. The first line contains a single integer \(n\), representing the number of elements in the array.
  2. The second line contains \(n\) space-separated integers.
  3. The third line contains an integer \(k\), representing the number of steps to rotate the array.

outputFormat

Output the rotated array to standard output (stdout) as space-separated integers on a single line.

## sample
6
1 2 3 4 5 6
2
5 6 1 2 3 4

</p>