All problems

Chunk a List into Size N

mediumPythonArrays

Riverbend Couriers works a queue of parcels with one small van. The van takes a fixed number of parcels per trip and drivers load strictly from the front, so trip one is the first few parcels and trip two the next few. The final trip is usually part-empty, and the run sheet must still show it: a parcel missing from the sheet is a parcel nobody delivers.

Task: Print the parcel numbers split into trips, one trip per line.

Input

Two lines. The first holds between 1 and 1000 integers separated by single spaces — the parcel numbers in queue order. The second holds a single integer n, the van's capacity, where 1 ≤ n ≤ 1000.

Output

One line per trip, holding up to n parcel numbers separated by single spaces, in queue order. Every parcel appears exactly once and the last line may hold fewer than n. If the van can take the whole queue, print one line.

Example:

Input:
1 2 3 4 5 6 7
3

Output:
1 2 3
4 5 6
7

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…