#K47797. Rotate Array

    ID: 28278 Type: Default 1000ms 256MiB

Rotate Array

Rotate Array

Given an array of integers and an integer k, rotate the array to the right by k steps.

The rotated array follows the formula below:

\( A = [a_0, a_1, \dots, a_{n-1}] \) becomes \( A' = [a_{n-k}, a_{n-k+1}, \dots, a_{n-1}, a_0, a_1, \dots, a_{n-k-1}] \).

Your task is to implement an efficient solution which reads the input from standard input (stdin) and writes the rotated array to standard output (stdout).

inputFormat

The input is given via standard input (stdin). The first line contains a sequence of space-separated integers representing the array. The second line contains a single integer k which indicates the number of steps to rotate the array.

outputFormat

Output the rotated array to standard output (stdout) as a sequence of space-separated integers.## sample

1 2 3 4 5
2
4 5 1 2 3