#K57647. Roman Numerals to Integer

    ID: 30467 Type: Default 1000ms 256MiB

Roman Numerals to Integer

Roman Numerals to Integer

Given a string representing a Roman numeral, convert it to an integer. Roman numerals consist of the following seven symbols: I, V, X, L, C, D, and M. The conversion rule is based on the observation that if a numeral appears before a larger numeral, its value is subtracted; otherwise, it is added. Mathematically, this process can be represented as: $$Integer = \sum_{i=1}^{n} {value(s_i)}$$ where $$value(s_i)$$ represents the integer value of the symbol at position $$i$$.

For example, the numeral "III" corresponds to 3, "IV" corresponds to 4, and "MCMXCIV" corresponds to 1994.

inputFormat

A single line containing a valid Roman numeral string.

outputFormat

Output a single integer, which is the equivalent value of the given Roman numeral.## sample

III
3