Roman numerals#2900

Roman numerals

1 second
256 megabytes
Easy

The given string consists of the characters 'I', 'V', 'X', 'L', 'C', 'D', and 'M'. You are to split this string into several segments so that each segment is a valid Roman numeral, and the sum of these numerals is minimized.

A valid Roman numeral is formed as follows. First, the symbol 'M' is written as many times as there are whole thousands in the number. For example, the number has two thousands, so its Roman numeral begins with "MM". Then, take the remainder after dividing by . Based on the number of hundreds in this remainder, you add: "C" for one hundred, "CC" for two, "CCC", "CD", "D", "DC", "DCC", "DCCC", or "CM" for three, four, ..., up to nine hundred, respectively. For , the remainder is , which has no hundreds, so nothing is added.

Next, take the remainder after dividing by . According to the number of tens, add "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", or "XC" (or nothing, if there are no tens). For , add "XL".

Then, take the remainder after dividing the original number by . Based on this, add "I", "II", "III", "IV", "V", "VI", "VII", "VIII", or "IX" for , , ..., respectively. If the remainder is zero, add nothing. For , you add "V".

Thus, the Roman numeral for is "MMXLV".

Additionally, there is the restriction that no symbol may appear more than three times in a row in Roman numerals. Therefore, valid Roman numerals exist only for numbers from to inclusive.

Input

The input contains a single non-empty string of at most characters, consisting of the specified uppercase Latin letters ('I', 'V', 'X', 'L', 'C', 'D', and 'M').

Output

Output a single number — the minimum possible sum of these numerals.

Examples

Example 1

Loading
Loading