#C8065. Cycle Rotate Array

    ID: 52006 Type: Default 1000ms 256MiB

Cycle Rotate Array

Cycle Rotate Array

You are given an array of integers and a non-negative integer k. Your task is to perform a right cyclic rotation on the array by k positions. A right cyclic rotation means that each element moves to the right by one position and the last element moves to the first position. More formally, given an array \(a_1, a_2, \dots, a_n\), after one right cyclic rotation the array becomes \(a_n, a_1, a_2, \dots, a_{n-1}\). For k rotations, you are required to compute the final state of the array.

Example:

Input:
5
1 2 3 4 5
2

Output: 4 5 1 2 3

</p>

Note: If k is greater than the size of the array, consider effective rotation i.e. \(k \mod n\).

inputFormat

The input is provided via standard input (stdin) in the following format:

  • The first line contains an integer n representing the number of elements in the array.
  • The second line contains n space-separated integers representing the array.
  • The third line contains the integer k, the number of right cyclic rotations to perform.

outputFormat

Output a single line to standard output (stdout) containing the elements of the array after performing k right cyclic rotations. The elements should be space-separated.

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