#C5448. Rotate Array

    ID: 49098 Type: Default 1000ms 256MiB

Rotate Array

Rotate Array

You are given an array of integers and a non-negative integer steps. Your task is to rotate the array to the right by the specified number of steps.

The rotation moves each element of the array to its right by the number of steps. Elements that fall off the end are wrapped around to the beginning. Formally, given an array \(A = [a_0, a_1, \ldots, a_{n-1}]\) and an integer \(k\), the rotated array is defined as:

[ A' = [a_{(n-k) \mod n}, a_{(n-k+1) \mod n}, \ldots, a_{(n-k-1) \mod n}] ]

If the array is empty, simply output an empty line.

inputFormat

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

  • The first line contains an integer n (\(0 \leq n \leq 10^5\)) representing the number of elements in the array.
  • The second line contains n space-separated integers representing the array elements.
  • The third line contains an integer steps (\(0 \leq steps \leq 10^9\)), the number of positions to rotate the array to the right.

outputFormat

Output the rotated array as space-separated integers on a single line to standard output (stdout). If the array is empty, output nothing.

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