#C14671. Shift List Elements
Shift List Elements
Shift List Elements
You are given a list of integers and an integer shift. Your task is to shift the elements of the list to the left by the given number of positions. The elements that fall off from the beginning are appended to the end of the list in the same order. The shifting operation supports negative shift values, which means a shift to the right. Mathematically, if the list has a length n, a shift value s is interpreted as shifting by $$ s \mod n $$ positions.
Example 1:
Input: list = [1, 2, 3, 4, 5], shift = 2 Output: [3, 4, 5, 1, 2]
Example 2:
Input: list = [10, 20, 30, 40, 50], shift = -1 Output: [50, 10, 20, 30, 40]
inputFormat
The input consists of three lines:
- An integer n representing the number of elements in the list.
- A line with n space-separated integers representing the list. If n is 0, this line will be empty.
- An integer shift representing the number of positions to shift the list.
outputFormat
Output a single line with the shifted list. Print the elements space-separated. If the list is empty, output an empty line.
## sample5
1 2 3 4 5
1
2 3 4 5 1
</p>