Aromatic Numbers


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem type
Allowed languages
Python

Problem Description

An aromatic number is a composite number formed by alternating Arabic digits and Roman numerals.

The form of an aromatic number is ARARAR…AR, where A is an Arabic digit and R is a Roman numeral.

Each Arabic digit A can be one of 0~9.

Each Roman numeral R can be one of I, V, X, L, C, D, M.

The corresponding values of the Roman numerals are as follows:

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

Each pair AR has a value, specifically a multiplied by the corresponding value of R.

The value represented by an aromatic number is obtained by applying the following addition and subtraction rules to the values of each included AR pair:

For each AR pair:

  • If there exists a next pair A′R′ after it, and the corresponding value of R is less than the corresponding value of R′, then the value of this AR pair should be subtracted when calculating the aromatic number's value.
  • Otherwise, the value of this AR pair should be added when calculating the aromatic number's value.

For example:

  • The value of 3M1D2C is 3×1000 + 1×500 + 2×100 = 3700
  • The value of 3X2I4X is 3×10 - 2×1 + 4×10 = 68

Given an aromatic number, please calculate its value.

Input Format

An aromatic number.

Output Format

An integer, representing the value of the aromatic number.

Constraints

The length of the aromatic number is in the range [2, 20].

Examples

Sample Input 1
3M1D2C
Sample Output 1
3700
Sample Input 2
2I3I2X9V1X
Sample Output 2
-16

Comments

There are no comments at the moment.