#K73312. Rotate Array

    ID: 33948 Type: Default 1000ms 256MiB

Rotate Array

Rotate Array

You are given an integer array and a non-negative integer \(k\). Your task is to rotate the array to the right by \(k\) steps. In other words, each element is shifted to the right by \(k\) positions and the elements that exit from the right end wrap around to the left end.

Formally, given an array \(a = [a_0, a_1, \dots, a_{n-1}]\), the rotated array \(b\) is defined as \(b_i = a_{(i - k) \bmod n}\) for \(0 \leq i < n\).

inputFormat

The first line 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 second line contains n space-separated integers representing the array.

outputFormat

Print the rotated array as a sequence of integers separated by spaces on a single line.## sample

7 3
1 2 3 4 5 6 7
5 6 7 1 2 3 4