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: rule = ["I","V","X","L","C","D","M"]
val = [1,5,10,50,100,500,1000]
while True:
    try:
        nums = input()
        ans = val[rule.index(nums[0])]

        for i in range(1,len(nums)):
            ans += val[rule.index(nums[i])]
            if rule.index(nums[i]) > rule.index(nums[i-1]):
                ans -= (2*val[rule.index(nums[i-1])])

        print(ans)
    except EOFError: break

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

while 1:
    try:
        s = input()
        sum = 0
        for i in range(len(s)-1):
            if t[s[i]] < t[s[i + 1]]:
                sum -= t[s[i]]
            else:
                sum += t[s[i]]
        print(sum+t[s[len(s)-1]])

    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)-1 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: 
def Roman_numerals(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:
		s=0
		string=input()
		for i in range(len(string)):
			tmp_now =Roman_numerals(string[i:i+1])
			tmp_next=Roman_numerals(string[i+1:i+2])
			if (tmp_now==1 and tmp_next==5):
				s+=-1
			elif (tmp_now==1 and tmp_next==10):
				s+=-1
			elif (tmp_now==10 and tmp_next==50):
				s+=-10
			elif (tmp_now==10 and tmp_next==100):
				s+=-10
			elif (tmp_now==100 and tmp_next==500):
				s+=-100
			elif (tmp_now==100 and tmp_next==1000):
				s+=-100
			else:
				s+=tmp_now
		print(s)

	except EOFError:
		break

Python: import sys

def solve():
    romans = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000, '\n': 0}
    for line in sys.stdin:
        cur, sum = 0, 0
        while cur + 1 < len(line):
            next_v = romans[line[cur + 1]]
            cur_v = romans[line[cur]]
            if next_v <= cur_v:
                sum += cur_v
            else:
                sum += next_v - cur_v
                cur += 1
            cur += 1
        print(sum)
    

if __name__ == "__main__":
    solve()

Python: # -*- coding: utf-8 -*-

import sys
import os


alab = {}
alab['I'] = 1
alab['V'] = 5
alab['X'] = 10
alab['L'] = 50
alab['C'] = 100
alab['D'] = 500
alab['M'] = 1000

for s in sys.stdin:
    s = s.strip()
    #print('s', s)

    A = []
    for c in s:
        A.append(alab[c])
    #print('A', A)

    for i in range(len(A) - 1):
        if A[i] < A[i+1]:
            A[i] *= -1
    #print('A', A)

    print(sum(A))

Python: while 1:
    try:
        roma = list(input())
    except:
        break
    l = len(roma)
    prev = ""
    ans = 0
    for i, r in enumerate(roma):
        if r == "I":
            if i != l-1:
                if roma[i+1] == "V" or roma[i+1] == "X":
                    ans -= 1
                else:
                    ans += 1
            else:
                ans += 1
        elif r == "V":
            ans += 5
        elif r == "X":
            if i != l-1:
                if roma[i+1] == "L" or roma[i+1] == "C":
                    ans -= 10
                else:
                    ans += 10
            else:
                ans += 10
        elif r == "L":
            ans += 50
        elif r == "C":
            if i != l-1:
                if roma[i+1] == "D" or roma[i+1] == "M":
                    ans -= 100
                else:
                    ans += 100
            else:
                ans += 100
        elif r == "D":
            ans += 500
        elif r == "M":
            ans += 1000

    print(ans)

Python: if __name__ == '__main__':

	B = ['I','V','X','L','C','D','M']
	C = [ 1 ,  5, 10, 50,100,500,1000]

	while True:
		try:
			A = list(input())
			leng = len(A)
			cnt = 0

			if leng == 1:
				cnt = C[B.index(A[0])]
			elif leng == 2:
				before = C[B.index(A[0])]
				after = C[B.index(A[1])]

				if before == after:
					cnt = C[B.index(A[0])] * 2
				elif before < after:
					cnt = after - before
				elif before > after:
					cnt = before + after

			else:
				cnt = C[B.index(A[0])]
				for i in range(1,leng):
					before = C[B.index(A[i-1])]
					after = C[B.index(A[i])]

					if before == after:
						cnt += C[B.index(A[i])]
					elif before < after:
						cnt = cnt -  before + (after - before)
					elif before > after:
						cnt = cnt +  after

			print(cnt)

		except EOFError:
			break

Python: import sys

C = [ 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
N = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]

def checkio(data, i = 0):
    return C[i]*(data // N[i]) + checkio(data % N[i], i + 1) if data else ''

for line in sys.stdin:
    n = int(line)
    print(checkio(n))

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