Queue RotatorEasy

Queue Rotator

EasyPractice library · +10 XPqueuedequesimulation

You are given a sequence of N integers and an integer K. You need to perform a rotation operation K times. A rotation operation consists of removing the first element of the sequence and appending it to the end of the sequence. Print the final sequence after K rotations.

Input

The first line contains two integers N and K, separated by a space. The second line contains N space-separated integers representing the initial sequence.

Output

Print the N space-separated integers representing the final sequence after K rotations.

Constraints

1 <= N <= 1000 0 <= K <= 1000 -1000 <= element <= 1000

Time limit 1 s (native code; slower languages get more)Memory 256 MB14 hidden tests

Example 1

Input
5 2
1 2 3 4 5
Output
3 4 5 1 2

After 2 rotations, 1 and 2 are moved to the end. Sequence becomes 3 4 5 1 2.

Example 2

Input
3 5
10 20 30
Output
30 10 20

K=5. N=3. 5 rotations is same as 5 % 3 = 2 rotations. Sequence becomes 30 10 20.

Hints