#C9131. Right Circular Shift
Right Circular Shift
Right Circular Shift
You are given a list of n integers and an integer k. Your task is to perform a right circular shift on the list exactly k times. In each right circular shift, the last element of the list moves to the front and all other elements shift one position to the right.
More formally, if the list is represented as \(A = [a_1, a_2, \ldots, a_n]\), then after one right circular shift the list becomes \([a_n, a_1, a_2, \ldots, a_{n-1}]\). After k shifts the result is given by performing the shift operation \(k\) times (or equivalently, \(k \mod n\) times if \(k > n\)).
inputFormat
The input is read from stdin and contains two lines:
- The first line contains two integers \(n\) and \(k\) separated by a space, where \(n\) is the number of elements in the list and \(k\) is the number of right circular shifts to perform.
- The second line contains \(n\) integers separated by spaces representing the list.
outputFormat
Output to stdout a single line containing the resulting list after performing the shifts. The elements should be printed as space-separated integers.
For example, for input:
4 1 1 2 3 4The output should be:
4 1 2 3## sample
4 1
1 2 3 4
4 1 2 3