|Contests||Virtual Contests||Problems||Submit||Runs Status||Rank List||Forum|
Symbols I, X, C and M can be repeated as needed (though never more than three times for I, X and C), so that 3 is represented as III, 27 as XXVII and 4865 as MMMMDCCCLXV. The symbols are always written from the highest value to the lowest, but for one exception: if a lower symbol precedes a higher one, it is subtracted from the higher. Thus 4 is written not as IIII but as IV, and 900 is written as CM. The rules for this subtractive behavior are the following: 1. Only I, X and C can be subtracted. 2. These numbers can only appear once in their subtractive versions (e.g., you can't write 8 as IIX). 3. Each can only come before symbols that are no larger than 10 times their value. Thus we can not write IC for 99 or XD for 490 (these would be XCIX and CDXC, respectively). Note that the first two words in this problem title are invalid Roman numerals, but the third is fine. Your task for this problem is simple: read in a set of Roman numeral values and output their sum as a Roman numeral.
2 XII MDL 4 I I I I 0
Case I: MDLXII Case II: IV