#C11674. Rotate List

    ID: 41016 Type: Default 1000ms 256MiB

Rotate List

Rotate List

Given an array of n integers and an integer k, your task is to rotate the list to the right by k steps. This means that the last k elements of the array will be moved to the front in the same order, and the rest of the elements will follow. If k is greater than n, then the effective number of rotations is k \mod n.

Example:

Input:  n = 5, k = 2
Array: [1, 2, 3, 4, 5]
Output: [4, 5, 1, 2, 3]

You are required to read input from standard input and write the output to standard output.

inputFormat

The first line of input contains two integers n and k, where n is the number of elements in the list and k is the number of steps to rotate. The second line contains n space-separated integers representing the array.

For example:

5 2
1 2 3 4 5

outputFormat

Output the rotated list as a sequence of space-separated integers in a single line.

For example:

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