#K80112. Rotate List

    ID: 35459 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 k times to the right. In other words, each element of the list is shifted right by k positions, and the elements that 'fall off' the end are wrapped around to the beginning.

Formally, given a list arr of length n and an integer k, the rotated list is defined as:

$$ rotated[i] = arr[(i + n - (k \mod n)) \mod n]$$

In the above formula, k \mod n is used to handle instances where k is greater than n or even zero.

Your solution should read input from stdin and output the result to stdout in the specified format.

inputFormat

The input consists of three lines:

  • The first line contains a single integer n — the number of elements in the list.
  • The second line contains n space-separated integers representing the list arr.
  • The third line contains a single integer k representing the number of times the list should be rotated to the right.

outputFormat

Output a single line containing the rotated list of integers. The integers should be printed in order and separated by a single space.

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