A sorting depot's conveyor belt can only lift parcels from the incoming chute in fixed batches of exactly 4 (or fewer, once the chute is nearly empty) into a small staging tray. A sequence of downstream stations, one after another, each ask the tray operator to hand over a specific number of parcels. Any parcels already lifted into the tray but not yet handed to a station must be kept for the next request rather than re-lifted or discarded, and once the chute runs dry every later station gets fewer parcels than it asked for (possibly none). Simulate the full sequence of station requests, in order, against one shared chute.
Line 1: a string S — the chute's contents from front to back, using only lowercase letters and digits (0 <= |S| <= 10^4). This line may be empty.
Line 2: an integer q — the number of station requests that follow (1 <= q <= 1000).
Next q lines: one integer n_i per line — the number of parcels station i asks for (0 <= n_i <= 10^4).
Print q lines, one per station request, in order. Each line has the form k:chars, where k is the number of parcels actually handed to that station (fewer than requested once the chute is exhausted) and chars is those parcels' characters concatenated in original order (empty if k is 0).
[a-z0-9]Example 1
Input
parceldepot12 3 4 5 10
Expected
4:parc 5:eldep 4:ot12
Explanation
The chute holds "parceldepot12" (13 characters). The first request for 4 hands over "parc" (k=4), consuming 4. The second request for 5 hands over the next 5 characters, "eldep" (k=5), consuming 9 total. The third request for 10 finds only 4 characters left ("ot12"), so it hands over just those 4 (k=4), fewer than asked because the chute is now empty. Output: "4:parc", "5:eldep", "4:ot12".
Example 2
Input
abc 4 2 5 1 3
Expected
2:ab 1:c 0: 0:
Explanation
The chute holds "abc" (3 characters). Request for 2 hands over "ab" (k=2), consuming 2. Request for 5 finds only 1 character left, "c" (k=1), consuming the last one. The chute is now empty, so the request for 1 returns nothing (k=0) and the request for 3 also returns nothing (k=0). Output: "2:ab", "1:c", "0:", "0:".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →