440. Reverse k Sized Sublists

0

Hard

Given a singly linked list of size N, you need to reverse the nodes of the linked list in groups of size K. If the length of the linked list is not a multiple of K, the remaining part should be left unchanged.

Input Format

The first line contains two space-separated integers N and K, representing the size of the linked list and the group size, respectively. The second line contains N space-separated integers, which represent the elements of the linked list.

Output Format

Print the modified linked list.

Example

Input

5 2
1 2 3 4 5

Output

2 1 4 3 5

Constraints

1<=N<=10^5
1<=K<=N
Elements of the linked list range from -10^9 to 10^9

Loading...

View Submissions

Console