#C12985. Rotate List
Rotate List
Rotate List
You are given a list of integers and an integer n. Your task is to rotate the list to the right by n positions. If n is negative, rotate the list to the left by |n| positions. If n is larger than the length of the list, use the effective rotation of n mod length(list).
Input/Output: All input is taken from standard input and all output is written to standard output. See the input and output descriptions for details.
inputFormat
The input consists of three lines:
- An integer m denoting the number of elements in the list.
- m space-separated integers representing the list elements. (If m is 0, this line will be empty.)
- An integer n which is the number of positions to rotate the list.
outputFormat
Output the rotated list as a single line of space-separated integers. If the list is empty, output nothing.
## sample5
1 2 3 4 5
2
4 5 1 2 3