#K74887. Rotate Array

    ID: 34297 Type: Default 1000ms 256MiB

Rotate Array

Rotate Array

You are given an array of integers and a non-negative integer \( k \). The task is to rotate the array to the right by \( k \) steps. This means that every element shifts to the right by \( k \) positions and the elements that fall off the end reappear at the beginning.

For example, if the input array is \( [1,2,3,4,5,6,7] \) and \( k = 3 \), then the rotated array will be \( [5,6,7,1,2,3,4] \). The rotation operation can be mathematically defined by

\( \text{rotateArray}(\text{arr}, k) = arr[-(k \mod n):] + arr[:-(k \mod n)] \), where \( n \) is the length of the array.

inputFormat

The input is read from standard input (stdin) and consists of three lines:

  1. The first line contains an integer \( n \), representing the number of elements in the array.
  2. The second line contains \( n \) space-separated integers, which are the elements of the array.
  3. The third line contains an integer \( k \), the number of positions by which the array should be rotated to the right.

outputFormat

Output a single line to standard output (stdout) containing the elements of the rotated array, separated by a single space.

## sample
7
1 2 3 4 5 6 7
3
5 6 7 1 2 3 4