#K2151. Batch Splitter

    ID: 24673 Type: Default 1000ms 256MiB

Batch Splitter

Batch Splitter

In this problem, you are given a list of integers and a batch size. Your task is to split the list into consecutive subarrays (batches) such that each batch contains exactly (k) elements, except possibly the last one, which may contain fewer elements if the total number of elements is not divisible by (k). For example, if the input list has 9 elements and the batch size is 3, the output should be three batches of 3 elements each. This problem tests your ability to manipulate arrays and work with input/output in standard streams.

inputFormat

The input is given via standard input (stdin) in the following format:

Line 1: An integer (n) representing the number of elements in the list. Line 2: (n) space-separated integers representing the list. Line 3: An integer (k) representing the batch size.

It is guaranteed that (1 \leq n \leq 10^5) and (1 \leq k \leq n).

outputFormat

Print the batches in order. For each batch, output its elements in one line separated by a single space. After printing all batches, output the total number of batches on a new line.## sample

9
1 2 3 4 5 6 7 8 9
3
1 2 3

4 5 6 7 8 9 3

</p>