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)??????????????????????????§????????°??????????????¨??¨?????????????????????
    ???????????????????????°??????????¬????????????¨????????????????????????????????????
    ??¨???????????????????????????????????????????????£????????????????????¨???????????¨???
    """
    roman_num = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}  # ???????????°???????????????????????????????????????

    decoded_number = 0  # ??¢????????¢??°??????????????????????????????
    my_stack = []
    for c in data:
        try:
            if len(my_stack) == 0:  # ???????????????????????????????????§??????????????§?????¨?????????????????????????????????
                my_stack.append(c)
            else:
                while len(my_stack) > 0 and roman_num[my_stack[-1]] < roman_num[c]:  # I???V ??? X???C ??????????????±?????????????????¨
                    decoded_number -= roman_num[my_stack.pop()]
                while len(my_stack) > 0:
                    decoded_number += roman_num[my_stack.pop()]
                my_stack.append(c)  # ???????????????????¬????????????¨??????????????????????????§??????????????????????????¨???XXIV(24)???????????£????????????????????§????????????
        except KeyError:
            raise ValueError
    while len(my_stack) > 0:
        try:
            decoded_number += roman_num[my_stack.pop()]
        except KeyError:
            raise ValueError
    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: sample = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}
while True :
    try :
        temp = input()
        f = temp[0]
        total = 0 
        for _ in temp[1:] :
            if sample[f] < sample[_] : total -= sample[f]
            else : total += sample[f]
            f = _
        total += sample[temp[-1]]
        print(total)
    except : break

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: mozi={"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000}
while True:
    try:
        N = list(input())
    except:
        break
    ans = i = 0
    while i < len(N):
        if i+1 < len(N) and mozi[N[i]] < mozi[N[i+1]]:
            ans += mozi[N[i+1]] - mozi[N[i]]
            i += 1
        else: ans += mozi[N[i]]
        i += 1
    print(ans)

Python: r={"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000}
while True:
    try:
        N = list(input())
    except:
        break
        
    ans = 0
    i = 0
    while i < len(N):
        if i+1 < len(N) and r[N[i]] < r[N[i+1]]:
            ans += r[N[i+1]] - r[N[i]]
            i += 1
        else: ans += r[N[i]]
        i += 1
    print(ans)

Python: while 1:
    try:
        s=input()
        ans=0
        for i in range(len(s)-1):
            if s[i]=="M":ans+=1000
            elif s[i]=="D":
                if s[i+1]=="M":ans-=500
                else:ans+=500
            elif s[i]=="C":
                if s[i+1]=="M" or s[i+1]=="D":ans-=100
                else:ans+=100
            elif s[i]=="L":
                if s[i+1]=="M" or s[i+1]=="D" or s[i+1]=="C":ans-=50
                else:ans+=50
            elif s[i]=="X":
                if s[i+1]=="M" or s[i+1]=="D" or s[i+1]=="C" or s[i+1]=="L":ans-=10
                else:ans+=10
            elif s[i]=="V":
                if s[i+1]=="M" or s[i+1]=="D" or s[i+1]=="C" or s[i+1]=="L" or s[i+1]=="X":ans-=5
                else:ans+=5
            elif s[i]=="I":
                if s[i+1]=="M" or s[i+1]=="D" or s[i+1]=="C" or s[i+1]=="L" or s[i+1]=="X" or s[i+1]=="V":ans-=1
                else:ans+=1
        if s[-1]=="M":ans+=1000
        elif s[-1]=="D":ans+=500
        elif s[-1]=="C":ans+=100
        elif s[-1]=="L":ans+=50
        elif s[-1]=="X":ans+=10
        elif s[-1]=="V":ans+=5
        elif s[-1]=="I":ans+=1
        print(ans)
    except:break

Python: def r2n(i):
    if i == "I":
        return 1
    elif i == "V":
        return 5
    elif i == "X":
        return 10
    elif i == "L":
        return 50
    elif i == "C":
        return 100
    elif i == "D":
        return 500
    elif i == "M":
        return 1000

while(1):
    try:
        n = list(input())
        prev = r2n(n[0])
        tot = r2n(n[0])
        for i in range(len(n)-1):
            now = r2n(n[i+1])
            if now > prev:
                tot = tot - prev*2 + now
                prev = now
            else:
                tot = tot + now
                prev = now
        print(tot)
    except EOFError:
        break

Python: import sys


def arabic(s):
    if s == "I":
        return 1
    elif s == "V":
        return 5
    elif s == "X":
        return 10
    elif s == "L":
        return 50
    elif s == "C":
        return 100
    elif s == "D":
        return 500
    elif s == "M":
        return 1000
    else:
        return -1


for i in sys.stdin:
    S = 0
    for j in range(len(i)):
        if arabic(i[j]) == -1:
            continue
            # print("ver1")
        elif j != 0 and arabic(i[j-1]) < arabic(i[j]):
                S = S - arabic(i[j-1]) * 2 + arabic(i[j])
                # print("ver2")
        else:
            S += arabic(i[j])
            # print("ver3")
        # print(str(S) + "!")
    print(S)

Python: def r_a(x) :
    if x == 'I' :
        return 1
    elif x == 'V' :
        return 5
    elif x == 'X' :
        return 10
    elif x == 'L' :
        return 50
    elif x == 'C' :
        return 100
    elif x == 'D' :
        return 500
    elif x == 'M' :
        return 1000
 
while True :
    try :
        R = list(input())
    except EOFError :
        break
    
    A = 0
    i = 0
    while True :
        if i == len(R)-1 :
            A += r_a(R[-1])
            break
        elif i > len(R)-1 :
            break
        a = R[i]
        b = R[i+1]
        if r_a(a) < r_a(b) :
            A +=  r_a(b) - r_a(a)
            i += 2
        else :
            A += r_a(a)
            i += 1
    print(A)