Splat, Inc.

Splat, Inc., the leading maker of paintballs for the paintball industry, ships its products to its customers in boxes. The boxes have been specially designed to hold paintballs. Each box is n paintballs wide, m paintballs tall, and 1 paintball deep. Before shipping, each box is filled by pouring a number of different-colored paintballs into it. Each color of paintball comes out of a separate feeder, and there are feeders for Red, Green, and Blue paintballs. Each feeder drops paintballs into a given box at a specific rate, and no two feeders drop from the same location. If all feeders are supposed to drop at the same point in time, then they drop their balls in the order Red, then Green, then Blue. The result is a mix of paintballs in the box. Customers do not really care that the paintballs in a given shipment are not all the same color, but they would like to know how many of each color they receive. Splat’s paintballs have some rather interesting characteristics. For instance, when a ball is dropped into the box, its final resting place is defined by the current state of the other balls in the box. A paintball can magically balance on top of another one, without the need to settle onto two balls in the previous row. The balls are never staggered; they always form nice, neat rows and columns. If a ball falls onto the bottom of the box, it just sits there. A ball is considered “free” if there is no ball immediately to its right, immediately to its left, or both. If a ball falls onto a free ball, it just sits there, forming a tower of two balls. If a third ball falls onto the tower of two, then the top ball falls to the left, and the second one falls to the right, forming a row of three balls where there once was a column of three. Figure 1 shows a tower of three free balls, and the result after the balls have fallen. If only one side of the tower is free, for instance if the column is against a wall of the box, then only one ball falls to the free side, and the other one stays on the stack, as shown in Figure 2. Each of the feeders drops balls into the box at a different rate. A feeder stops feeding when the last ball it dropped came to rest just inside the box (i.e., in the top row), so that there is still room for the top to be put on the box. Your job is to determine how many balls of each color are in the box when it is filled. Input The input consists of a number of cases, one per line. Each case consists of 8 integers, separated by white space. The first integer, n, is the width of the box. The second integer, m, is the height of the box. n and m will be no less than 1 and no greater than 50. The next three numbers are the intervals, in seconds, between the dropping of paintballs from the Red, Green, and Blue feeders, respectively. For example, a value of 1 means that one paintball is dropped every 1 second, starting on the first second. A value of 4 means that one paintball is dropped every 4 seconds, starting on the first second. A value of 0 means that no paintballs of that color will be dropped. The last 3 integers denote the column

2/2 location of each of the Red, Green, and Blue feeders. These will lie between 0 and n − 1, inclusive. The end of input is signified by a line with eight zeros. Output For each case, output the word ‘Case’ followed by one space, then the case number, a colon, a space and the number of Red, Green, and Blue paintballs, and the number of empty spaces in the box once it is full, separated by one space. Sample Input 5 5 1 50 50 4 0 2 20 15 1 50 1 5 10 15 00000000 Sample Output Case 1: 8 7 6 4 Case 2: 100 28 98 74