#C8410. Rotate Array

    ID: 52390 Type: Default 1000ms 256MiB

Rotate Array

Rotate Array

You are given an array of integers and an integer ( k ). Your task is to rotate the array to the right by ( k ) steps. In other words, move the last ( k ) elements of the array to the beginning in the same order, and shift the remaining elements to the right.

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

Note that if ( k ) is greater than the length of the array ( n ), rotating the array ( k ) times is equivalent to rotating it ( k \bmod n ) times. Formally, given an array ( A = [a_1, a_2, \dots, a_n] ), the resulting array after rotation should be
( [a_{n-k+1}, a_{n-k+2}, \dots, a_n, a_1, a_2, \dots, a_{n-k}] ).

inputFormat

The input is given via standard input. The first line contains an integer ( n ) representing the number of elements in the array. The second line contains ( n ) space-separated integers which are the elements of the array. The third line contains an integer ( k ), the number of steps by which the array should be rotated.

outputFormat

Print the rotated array as space-separated integers in a single line to standard output.## sample

5
1 2 3 4 5
2
4 5 1 2 3