#K59857. Roman Numeral to Integer Converter

    ID: 30957 Type: Default 1000ms 256MiB

Roman Numeral to Integer Converter

Roman Numeral to Integer Converter

In this problem, you are required to convert a given Roman numeral into its integer representation. The Roman numeral system consists of seven symbols: I (1), V (5), X (10), L (50), C (100), D (500), and M (1000). Sometimes, a smaller numeral placed before a larger numeral indicates subtraction. For instance, IV represents 4 and IX represents 9.

The conversion follows these rules:

  • If a numeral is not preceded by a smaller numeral, add its value.
  • If it is preceded by a smaller numeral, subtract the smaller numeral's value.

You may refer to the formulas: $$ I=1,\ V=5,\ X=10,\ L=50,\ C=100,\ D=500,\ M=1000 $$ for the respective values.

inputFormat

The input consists of a single line containing a valid Roman numeral string (e.g., MMXVIII). The input is provided via stdin.

outputFormat

Output the integer value corresponding to the given Roman numeral on a single line via stdout.

## sample
III
3