Roman to Integer

Medium 40 XPStringsHashing

Commonly asked at Amazon, Microsoft, Facebook

Convert a Roman numeral to an integer. Values: I=1, V=5, X=10, L=50, C=100, D=500, M=1000. A smaller value before a larger one is subtracted (IV = 4, IX = 9, XL = 40, CM = 900).

Input
One Roman numeral (1 to 3999).
Output
Its integer value.

Sample 1

Input

MCMXCIV

Output

1994

Read input with input() (no prompt message) and print only the answer. Run tries the Input box; Submit checks all test cases.

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.
The solution unlocks after 3 submissions.