#K50437. Rotate Array Right

    ID: 28864 Type: Default 1000ms 256MiB

Rotate Array Right

Rotate Array Right

You are given an array A of size N and a non-negative integer K. Your task is to rotate the array to the right by K steps.

Rotating the array means moving the last element to the front and shifting the rest of the elements one position to the right. If K is greater than N, then rotating by K steps is equivalent to rotating by \(K \bmod N\) steps.

The elements of the array are integers and the result should be printed as a space-separated list.

inputFormat

The input is given through standard input (stdin) in two lines:

  • The first line contains two integers: N (the size of the array) and K (the number of steps to rotate).
  • The second line contains N space-separated integers representing the array A.

outputFormat

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

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