All problems

Roman to Integer

mediumPythonStringsMath

Hartfield Museum labels each exhibit with the year it was made in Roman numerals, the way the stonework and the old film title cards do. The catalogue behind the scenes stores years as ordinary numbers, so the import tool has to read a label and work out which year it means. The symbols are I = 1, V = 5, X = 10, L = 50, C = 100, D = 500 and M = 1000. They are normally written largest first and count upward, except that a smaller symbol placed immediately before a larger one counts downward instead -- which is how IV means 4 and IX means 9.

Task: Print the whole number that the Roman numeral stands for.

Input

A single line holding one valid Roman numeral, 1 to 15 characters, all upper case, using only the seven symbols above.

Output

One line holding a single integer, the value of the numeral.

Example:

Input:
MCMXCIV

Output:
1994

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…