#K41207. Rotate Sequence

    ID: 26814 Type: Default 1000ms 256MiB

Rotate Sequence

Rotate Sequence

You are given a sequence of integers and a number ( k ). Your task is to rotate the sequence to the right by ( k ) steps. More formally, if the original sequence is ( a_1, a_2, \ldots, a_n ), then after one rotation the sequence becomes ( a_n, a_1, \ldots, a_{n-1} ). After ( k ) rotations, since the rotations are cyclic, the effective rotation is ( k \bmod n ).

For example, given the sequence [1, 2, 3, 4, 5] and ( k = 2 ), the rotated sequence is [4, 5, 1, 2, 3].

inputFormat

The input is read from standard input (stdin) and consists of space-separated integers. The first integer is ( n ), the number of elements in the sequence. This is followed by ( n ) integers representing the sequence. Finally, an integer ( k ) is provided, representing the number of rotations.

outputFormat

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

5 1 2 3 4 5 2
4 5 1 2 3