#K42052. Split Linked List into Parts

    ID: 27001 Type: Default 1000ms 256MiB

Split Linked List into Parts

Split Linked List into Parts

You are given a singly linked list and an integer k. Your task is to split the linked list into k consecutive parts such that the size of each part is as equal as possible. More formally, let n be the total number of nodes in the list. Then, each part should have a length of either \(\lfloor n/k \rfloor\) or \(\lfloor n/k \rfloor+1\), and the first \(n \bmod k\) parts should have one extra node. If there are not enough nodes, some parts may be empty.

The parts must remain in the same order as in the original list. For each part, output the node values in order separated by a single space. If a part is empty, output an empty line.

inputFormat

The input is given via standard input. The first line contains an integer n representing the number of nodes in the linked list. If n is greater than 0, the second line contains n integers representing the node values (in order). The third line contains an integer k representing the number of parts to split the list into.

outputFormat

Print exactly k lines to standard output. Each line should contain the values of the corresponding part of the linked list separated by a single space. If a part is empty, print an empty line.

## sample
10
1 2 3 4 5 6 7 8 9 10
3
1 2 3 4

5 6 7 8 9 10

</p>