#C10592. Rotate List

    ID: 39814 Type: Default 1000ms 256MiB

Rotate List

Rotate List

Given a list of n integers and an integer k, rotate the list to the right by k steps. The rotation is defined as moving the last k mod n elements to the front of the list. That is, if you have a list L, after rotation the list becomes:

L[k:] + L[:k]

Note that if k is greater than n, you should use k mod n to determine the effective rotation.

For example, if n = 5, L = [1,2,3,4,5] and k = 2, then the rotated list is [4, 5, 1, 2, 3].

inputFormat

The input is given via stdin and consists of three lines:

  • The first line contains an integer n, denoting the number of elements in the list.
  • The second line contains n space-separated integers representing the list.
  • The third line contains an integer k representing the number of rotation steps to the right.

outputFormat

Output the rotated list as space-separated integers in a single line to stdout.

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