#C14172. Rotate List

    ID: 43792 Type: Default 1000ms 256MiB

Rotate List

Rotate List

You are given a list of integers and an integer k. Your task is to rotate the list to the right by k positions. That is, each element is shifted to the right and the elements that overflow appear at the beginning of the list.

If n is the length of the list and k > n, then you should perform \(k \mod n\) rotations. For example, given the list [1, 2, 3, 4, 5, 6, 7] and \(k = 3\), the resulting list is [5, 6, 7, 1, 2, 3, 4].

This problem tests your ability to handle array manipulations and modular arithmetic.

inputFormat

The input is read from stdin and consists of three lines:

  1. The first line contains a single integer n representing the number of elements in the list.
  2. The second line contains n space-separated integers which are the elements of the list.
  3. The third line contains a single integer k indicating the number of positions to rotate the list.

outputFormat

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

## sample
7
1 2 3 4 5 6 7
3
5 6 7 1 2 3 4