403. LL - k Reverse

0

Medium

Write a function that takes a linked list **L** and reverses it by grouping **k** elements at a time. It is guaranteed that **k** is a factor of the size of the list. The function should modify the original list without creating a new one.

Input Format

The first line of input contains two space-separated integers **N** and **K**. The second line of input contains **N** space-separated integral elements of the linked list.

Output Format

Display the linked list after reversing every **k** elements.

Example

Input

9 3 9 4 1 7 8 3 2 6 5

Output

1 4 9 3 8 7 5 6 2

Constraints

0 <= N <= 10^6 0 <= K <= 10^6
Loading...

View Submissions

Console