#C6506. Rotate Array

    ID: 50274 Type: Default 1000ms 256MiB

Rotate Array

Rotate Array

You are given an array of integers and an integer k. Your task is to rotate the array to the right by k steps. For each element at index i in the original array, its new position in the rotated array is given by the formula $$ new\_index = (i + k) \mod n $$, where n is the number of elements in the array.

The rotation is performed in a cyclic manner. For example, if the array is [1, 2, 3, 4, 5, 6, 7] and k is 3, then the rotated array will be [5, 6, 7, 1, 2, 3, 4].

inputFormat

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

  • The first line contains an integer n denoting the number of elements in the array.
  • The second line contains n space-separated integers representing the elements of the array.
  • The third line contains an integer k specifying the number of steps to rotate the array.

outputFormat

Output the rotated array to stdout as a sequence of space-separated integers on a single line.

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