#K93747. Left Rotation of an Array

    ID: 38488 Type: Default 1000ms 256MiB

Left Rotation of an Array

Left Rotation of an Array

Given an array of integers and an integer n, perform a left rotation on the array n times. Specifically, if the length of the array is m, then the effective rotation is performed by taking n mod m rotations. In mathematical notation, if the original array is \(A = [A_0, A_1, \dots, A_{m-1}]\) and \(r = n \mod m\), the rotated array becomes:

[ A' = [A_r, A_{r+1}, \dots, A_{m-1}, A_0, A_1, \dots, A_{r-1}] ]

If the array is empty, the output is an empty array.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains an integer \(m\) (\(0 \le m \le 10^5\)), representing the number of elements in the array.
  • If \(m > 0\), the second line contains \(m\) space-separated integers representing the array elements.
  • The next line contains an integer \(n\), the number of left rotations to perform.
  • If \(m = 0\), the second line can be omitted.

outputFormat

Output the rotated array as a single line of space-separated integers to standard output (stdout). If the array is empty, output nothing.

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