#C7176. Rotate Array to the Right

    ID: 51018 Type: Default 1000ms 256MiB

Rotate Array to the Right

Rotate Array to the Right

Given an array of integers and a non-negative integer k, your task is to rotate the array to the right by k positions.

The rotation should be performed in such a way that the last k elements of the array move to the beginning, while the remaining elements shift to the right.

Note: If k is greater than the size of the array, then it should be taken modulo the length of the array. If the array is empty, simply output an empty result.

The problem will be solved by reading input from stdin and printing the result to stdout.

inputFormat

The input is taken from stdin and has the following format:

  1. An integer n denoting the number of elements in the array.
  2. A line containing n space-separated integers representing the elements of the array.
  3. An integer k representing the number of positions to rotate the array to the right.

If n is zero, the array is empty.

outputFormat

Output a single line to stdout containing the rotated array. The elements should be space-separated. If the array is empty, output nothing.

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