Generalized Roman Numerals

No attempts yetTime limit3sMemory limit256 MB

Problem

The Romans wrote numbers with the letters I, V, X, L and C, worth 1, 5, 10, 50 and 100. XXXVII is 10+10+10+5+1+110+10+10+5+1+1, that is 37. They usually wrote the letters in non-increasing order, but a single smaller letter placed in front of a larger one is subtracted from it, so IV is 4, IX is 9, XL is 40 and XC is 90. They wrote 94 as XCIV.

VIC is not a traditional Roman numeral, but you can read it as another way of writing 94: VI is 6, so VIC is 1006100-6. In general, if two expressions aa and bb have values v(a)v(a) and v(b)v(b), then v(ab)=v(a)+v(b)v(ab) = v(a) + v(b) when v(a)v(b)v(a) \ge v(b), and v(ab)=v(b)v(a)v(ab) = v(b) - v(a) otherwise.

This rule is ambiguous, because a different order of evaluation can give a different value. Take IVX. IV is 4 and X is 10, so that order makes IVX 6. But I is 1 and VX is 5, so the other order makes IVX 4. To fix an order you can add parentheses. Given a string of these letters, find every value it can take.

Input

The input holds several test cases. Each line holds one string made only of the letters I, V, X, L and C, of length 1 to 50. A line holding a single 0 ends the input.

Output

For each test case print one line of the form Case i: v1 v2 .... Here ii is the number of the test case counting from 1, and v1,v2,v_1, v_2, \dots are the distinct values the string can take, listed in increasing order. Separate the values with single spaces.