#C13783. Roman Numeral Conversion

    ID: 43359 Type: Default 1000ms 256MiB

Roman Numeral Conversion

Roman Numeral Conversion

Given a Roman numeral R, convert it to its corresponding integer value. A Roman numeral consists of the symbols \(I, V, X, L, C, D, M\) with the following values:

  • \(I=1\)
  • \(V=5\)
  • \(X=10\)
  • \(L=50\)
  • \(C=100\)
  • \(D=500\)
  • \(M=1000\)

The numeral will be provided in either uppercase or lowercase letters. The numeral must follow these standard rules:

  • Symbols \(I, X, C,\) and \(M\) may be repeated, but no more than three times consecutively.
  • Symbols \(V, L,\) and \(D\) cannot be repeated.
  • Subtractive notation is used; for example, \(IV\) represents 4 and \(IX\) represents 9.
  • If the numeral contains any invalid sequence (for example, "IIII" or "VV"), then it should be considered invalid.

Your task is to write a program that reads a single Roman numeral from the standard input (stdin) and prints its corresponding integer value to the standard output (stdout). If the numeral is invalid, output Invalid Roman numeral.

inputFormat

A single line containing a Roman numeral string.

outputFormat

A single line with the integer value corresponding to the Roman numeral, or the string Invalid Roman numeral if the input is invalid.## sample

XIV
14