A post master wishes to automate the sorting operation at his post office, since he finds that on an average the number of people assigned to the sorting operation are either heavily loaded or idle, ultimately resulting in loss of man hours that could have been efficiently used. He comes up with an idea of an automatic sorting machine that has a fixed capacity to hold the input letters and that sorts the letters at a fixed output rate. Depending upon the arrival of letters to the sorter, once the sorter is full of letters, the excess letters that would cause the sorting box to overflow have to be dropped into a bin to be manually sorted afterwards.
You are working for a company that has been called by the postmaster for a meeting to demonstrate a software simulation of the sorter. The following scenarios need to be shown in the simulation to him:
At the beginning of every second:
Input consists of multiple testcases.
The first line of each testcase contains three integers: C R M (1 ≤ M ≤ 100; 1 ≤ R ≤ C ≤ 20,000) representing the capacity of the sorter, the fixed-rate of sorting of the sorter and the number of messages.
The following M lines contain one integer each, i-th line representing the number of letters that arrived, at time i. Each of these integers will be in the inclusive range [0,1000].
Input ends with a line containing three zeros.
Output to each test case must begin with a line containing "Case #
Current time (The i-th line will be just i).
Letters received (Same as the input for the i-th line).
Letters sorted (Number of letters the sorter sorted at this unit of time; must be less than or equal to R).
Sorter balance (Number of pending letters in the sorter; must be less than or equal to C).
Number of letters dumped into the manual sorter bin.
There should be a blank line after each test-case.