#K56. Rotate Array

    ID: 30100 Type: Default 1000ms 256MiB

Rotate Array

Rotate Array

You are given an array of integers and a number of steps. Your task is to rotate the array to the right by the given number of steps.

The rotation operation is defined as follows: if the array has n elements and you need to rotate it by k steps, then you should move the last \( k \mod n \) elements to the beginning of the array, and shift the remaining elements to the right. Formally, if \( k' = k \mod n \), then the rotated array is:

\[ \text{rotated} = [a_{n-k'}, a_{n-k'+1}, \dots, a_n, a_1, a_2, \dots, a_{n-k'}] \]

For example, if the input array is [1, 2, 3, 4, 5] and the number of steps is 2, the result should be [4, 5, 1, 2, 3].

inputFormat

The first line of input contains two integers \( n \) and \( k \), where \( n \) is the number of elements in the array and \( k \) is the number of steps to rotate the array.

The second line contains \( n \) space-separated integers representing the elements of the array.

outputFormat

Output the rotated array on a single line, with the elements separated by a single space.

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

</p>