#K9111. Array Rotation

    ID: 37903 Type: Default 1000ms 256MiB

Array Rotation

Array Rotation

You are given an array of integers and a non-negative integer k. Your task is to rotate the array to the right by k steps. That is, each element of the array is shifted rightward by k positions, and the elements at the end of the array wrap around to the beginning.

The operation can be mathematically viewed as follows. Let the array be \(A = [a_0,a_1,\dots,a_{n-1}]\). After a rotation of k steps, the array becomes

[ A' = [a_{(n-k)\bmod n}, a_{(n-k+1)\bmod n}, \dots, a_{(n-k-1)\bmod n}] ]

Note that if k is greater than the length of the array n, you should first reduce it modulo n.

inputFormat

The first line of input contains two integers n and k separated by a space:

  • n: The number of elements in the array.
  • k: The number of steps to rotate the array to the right.

The second line contains n space-separated integers representing the array elements. If n is 0, the second line will be empty.

outputFormat

Output the rotated array as a sequence of space-separated integers in a single line. If the rotated array is empty, output nothing.

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