Mining in Starcraft

In Star Craft, there are two main resources: minerals and vespene gas (“gas” for short). You can ask SCVs to mine minerals and collect gas. • If a “mineral” command is given to an SCV, it can get 8 units of minerals after t1 unit time. • If a “gas” command is given to an SCV, it can get 8 units of gas after t2 unit time. You can only give a command to an SCV after its previous command is finished. You can build new SCVs, each costing 50 units of mineral and takes t3 unit time. Those minerals are consumed at the beginning of the process, and you can build at most one SCV at a time (i.e. you cannot start building another SCV before the previous SCV is finished). Initially, you have 50 units of minerals and 4 SCVs. Your task is to have at least p1 units of minerals and at least p2 units of gas, as soon as possible. Input Each test case contains 5 integers t1, t2, t3, p1, p2 (1 ≤ t1, t2, t3 ≤ 10, 0 ≤ p1, p2 ≤ 100). The last case is followed by t1 = t2 = t3 = p1 = p2 = 0, which should not be processed. There will be at most 1000 test cases, all are randomly generated. Output For each test case, print the shortest time T in the first line, followed by the plan (if multiple optimal plans exist, any will do). Each line in the plan has 3 kinds of format: • t 0—buildanewSCVattimet • t i 1 — give “mineral” command to the i-th SCV. • t i 2 — give “gas” command to the i-th SCV. Print a blank line after each test case, including the last test case. SCVs are numbered 1, 2, 3, . . . Initial SCVs are numbered 1..4, newly built SCVs are numbered in the same order they’re built. Important: At time T, all the SCVs must be idle, and there should be no SCV being built. Sample Input 10 9 8 0 10 4 10 9 32 72 00000

2/2 Sample Output Case 1: 9 012 022 Case 2: 24 00 011 021 031 041 412 422 432 442 14 1 2 14 2 2 14 3 2 14 4 2 14 5 2