#C14494. Roman Numerals to Integer Conversion

    ID: 44149 Type: Default 1000ms 256MiB

Roman Numerals to Integer Conversion

Roman Numerals to Integer Conversion

This problem requires you to convert a given Roman numeral to its corresponding integer value. Roman numerals are based on the following symbols:

  • I represents 1
  • V represents 5
  • X represents 10
  • L represents 50
  • C represents 100
  • D represents 500
  • M represents 1000

The conversion follows the rule that when a smaller numeral appears before a larger one, it is subtracted, otherwise it is added. Formally, if we denote the value of a Roman numeral symbol by \( v(r) \), then reading from right to left we have:

\( total = \sum_{i=1}^{n} {((v_i \geq v_{i-1}) ? v_i : -v_i)} \)

Your task is to implement this conversion.

inputFormat

The input is given via standard input (stdin) as a single line containing one string, which is a valid Roman numeral. The numeral will be in uppercase letters.

Example: MCMXCIV

outputFormat

Output the integer value corresponding to the given Roman numeral on standard output (stdout).

Example: For input MCMXCIV, output should be 1994.

## sample
III
3