Go: package main

import (
	"bufio"
	"os"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	dict := make(map[string]int)
	dict[" "] = 0
	dict["I"] = 1
	dict["V"] = 5
	dict["X"] = 10
	dict["L"] = 50
	dict["C"] = 100
	dict["D"] = 500
	dict["M"] = 1000
	for scanner.Scan() {
		line := strings.Split(scanner.Text(), "")
		line = append(line, " ")
		sum := 0
		for i := 0; i < len(line)-1; i++ {
			if dict[line[i]] < dict[line[i+1]] {
				sum -= dict[line[i]]
			} else {
				sum += dict[line[i]]
			}
		}
		fmt.Println(sum)
	}
}

Python: import sys


def decode_roman_number(data):
    """ ???????????°????????¢????????¢??°??????????????????
    ????????§??????????????¨????????????????????§???I, V, X??????????????????????????????????????¢????????¢??°???????????????????????????

    ?????¬????????????????????????????????????????????????????????????????????????????????§???????????°??????????????¨???????????¨???????????§????????????????????????????????????????????????
    ?¬??????????????????????????°????????????£?????????????????§????????°(???: V ??? I)??????????????????????????§????????°??????????????¨??¨?????????????????????
    ??????????????§???????????£?????????????????§????????°(???: I ??? V)??????????????????????????§????????°??????????????¨??¨?????????????????????
    ???????????????????????°??????????¬????????????¨????????????????????????????????????
    ??¨???????????????????????????????????????????????£????????????????????¨???????????¨???
    """
    numbers = []
    for d in data:
        if d == 'I':
            numbers.append(1)
        elif d == 'V':
            numbers.append(5)
        elif d == 'X':
            numbers.append(10)
        elif d == 'L':
            numbers.append(50)
        elif d == 'C':
            numbers.append(100)
        elif d == 'D':
            numbers.append(500)
        elif d == 'M':
            numbers.append(1000)
        else:
            raise ValueError

    decoded_number = 0  # ??¢????????¢??°??????????????????????????????
    my_stack = []
    for n in numbers:
        if len(my_stack) == 0:  # ???????????????????????????????????§??????????????§?????¨?????????????????????????????????
            my_stack.append(n)
        else:
            while len(my_stack) > 0 and my_stack[-1] < n:  # I???V ??? X???C ??????????????±?????????????????¨
                decoded_number -= my_stack.pop()
            while len(my_stack) > 0:
                decoded_number += my_stack.pop()
            my_stack.append(n)  # ???????????????????¬????????????¨??????????????????????????§??????????????????????????¨???XXIV(24)???????????£????????????????????§????????????
    while len(my_stack) > 0:
        decoded_number += my_stack.pop()
    return decoded_number


if __name__ == '__main__':
    #
    for line in sys.stdin:
        data = line.strip()
        # data = 'CCCCLXXXXVIIII'
        # data = 'MCMXLV'

        # ???????????°???????§£???
        ans = decode_roman_number(data)

        # ???????????¨???
        print(ans)

Python: def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())

for l in range(len(N)):
    num = N[l]
    ans = 0
    d = 0
    d_past = 9999
    for i in range(len(num)):
        if num[i] == "I":
            d = 1
        elif num[i] == "V":
            d = 5
        elif num[i] == "X":
            d = 10
        elif num[i] == "L":
            d = 50
        elif num[i] == "C":
            d = 100
        elif num[i] == "D":
            d = 500
        elif num[i] == "M":
            d = 1000

        if d_past < d:
            ans -= d_past * 2

        ans += d
        d_past = d
    print(ans)

Python: r_dict = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}
while True:
    try:
        s = 0
        b = 0
        r = input()
        for i in range(len(r))[::-1]:
            a = r_dict[r[i]]
            if b <= a:
                s += a
            else:
                s -= a
            b = a
        print(s)
    except:
        break

Python: import sys

def dec_num(x):
    for i in range(len(x)):
        if x[i] == 2:
            x[i] = 5
        elif x[i] == 3:
            x[i] = 10
        elif x[i] == 4:
            x[i] = 50
        elif x[i] == 5:
            x[i] = 100
        elif x[i] == 6:
            x[i] = 500
        elif x[i] == 7:
            x[i] = 1000

def to_index(x):
    if x == 1:
        return 1
    elif x == 5:
        return 2
    elif x == 10:
        return 3
    elif x == 50:
        return 4
    elif x == 100:
        return 5
    elif x == 500:
        return 6
    elif x == 1000:
        return 7


def toNum(x):
    result = 0
    tmp = x[0]
    for i in range(len(x)):
        if tmp < x[i]:
            result += x[i]-tmp
        elif i <= len(x) and x[i] < x[i+1]:
            result += 0
        else:
            result += x[i]
        tmp = x[i] 

    return result

for line in sys.stdin.readlines():
    line = line.translate(str.maketrans('IVXLCDM', '1234567'))
    num = list(map(int, (' '.join(line)).split()))
    dec_num(num)
    print(toNum(num))

Python: r={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
import sys
for e in sys.stdin:
 a=0
 n=[r[c]for c in e.strip()]
 for i in range(len(n)):
  if i+1<len(n)and n[i]<n[i+1]:a-=n[i]
  else:a+=n[i]
 print(a)

Python: table = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}

try:
    while True:
        a = [table[c] for c in input()] + [0]
        result = 0
        for n1, n2 in zip(a, a[1:]):
            result += n1 if n1 >= n2 else -n1

        print(result)

except EOFError:
    exit()

Python: import sys
if sys.version_info[0]>=3: raw_input=input

def main(roman):
	m={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
	r=0
	for i in range(len(roman)):
		r+=m[roman[i]]*(1 if i==len(roman)-1 or m[roman[i]]>=m[roman[i+1]] else -1)
	print(str(r))

if __name__=='__main__':
	try:
		while True:
			main(raw_input().rstrip())
	except EOFError:
		pass

Python: import sys

d = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}

for s in sys.stdin:
    s = [d[c] for c in s.strip()] + [0]
    n = 0
    for i, x in enumerate(s[:-1]):
        if x >= s[i + 1]:
            n += x
        else:
            n -= x
    print(n)

Python: dic = dict(I=1, V=5, X=10, L=50, C=100, D=500, M=1000)
while True:
    try:
        nums = list(map(lambda x: dic[x], list(input())))
    except:
        break
    ans = 0
    for i in range(1, len(nums)):
        if nums[i - 1] >= nums[i]:
            ans += nums[i - 1]
        else:
            ans -= nums[i - 1]
    print(ans + nums[-1])

Python: val={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
rom=['I','V','X','L','C','D','M']
while True:
    try:
        s = list(input().strip())
        w = 0
        c = s[0]
        s = s[1:]
        while len(s) > 0:
            if rom.index(s[0]) <= rom.index(c):
                w += val[c]
            else:
                w -= val[c]
            c = s[0]
            s = s[1:]

        w += val[c]
        print(w)

    except EOFError:
        break

Python: while True:
    try:
        Roma = input()
        Roma = Roma.replace('IV', 'IIII')
        Roma = Roma.replace('IX', 'VIIII')
        Roma = Roma.replace('XL', 'XXXX')
        Roma = Roma.replace('XC', 'LXXXX')
        Roma = Roma.replace('CD', 'CCCC')
        Roma = Roma.replace('CM', 'DCCCC')
        Roma = list(Roma)
        Num = 1000 * Roma.count('M') + 500 * Roma.count('D') + 100 * Roma.count('C') + 50 * Roma.count('L') + 10 * Roma.count('X') + 5 * Roma.count('V') + Roma.count('I')
        print(Num)
        
    except EOFError:
        break