Problem:


ローマ数字

古代ローマでは数を数えることは難しい仕事でした。アラビア数字の 0,1,2,3,…, 9 はまだ流布していませんでした。その代わり次のような記号が使われていました。

アラビア数字ローマ数字アラビア数字ローマ数字アラビア数字ローマ数字

1I11XI30XXX

2II12XII40XL

3III13XIII50L

4IV14XIV60LX

5V15XV70LXX

6VI16XVI80LXXX

7VII17XVII90XC

8VIII18XVIII100C

9IX19XIX500D

10X20XX1000M

I は 1、 V は 5、 X は 10、 L は 50、 C は 100、 D は 500、 M は 1000、 他の例は上の表を見てください。小さい数が大きい数に続いている、つまり右側にあるときは足し算をします。小さい数が大きい数の前に、つまり左にあるときは、大きい数から小さい数を引きます。大きい数字の前にあって引き算を表す小さな数字は一回の引き算あたりひとつしかありません。

ローマ数字をアラビア数字（通常の数字）の表記（10 進表示）に変換して出力するプログラムを作成してください。ただし、与えられるローマ数字は上記のルールにのみ従っています(実際のローマ数字の表記にはもっと細かいルールがありますが、ここでは考慮する必要はありません。たとえば、実際のローマ数字ではI はV かX から、X はL かC から、C はD かM からしか引き算しませんし、同じローマ数字は４つ以上（または５つ以上）足し並べることはありません。)

Input

複数のデータセットが与えられます。それぞれのデータセットにローマ数字（半角大文字のI, V, X, L, C, D ,M で表される連続した文字列）が１行に与えられます。与えられるローマ数字の文字列の長さはおのおの 100 以下です。

データセットの数は 50 を超えません。

Output

各データセットに対し、アラビア数字（整数）を１行に出力して下さい。

Sample Input

IV
CCCCLXXXXVIIII
CDXCIX

Output for the Sample Input

4
499
499



Sample input:
IV
CCCCLXXXXVIIII
CDXCIX


Sample output:
4
499
499

Submission status: Accepted

Solution code:
import sys

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

for s in sys.stdin.read().rstrip().split('\n'):
    r = 0
    for i in range(len(s)):
        r += d[s[i]]
        if i > 0 and (d[s[i]] > d[s[i-1]]):
            r -= d[s[i-1]]*2
    print r

Submission status: Accepted

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

try:
    while True:
        x=[]
        line = raw_input()
        tmp = roman[line[0]]
        x.append(tmp)
        for c in line[1:]:
            tmp = roman[c]
            if x[-1]<tmp: x[-1] = -x[-1]
            x.append(tmp)
        print sum(x)
except:
    pass

Submission status: Accepted

Solution code:
R = dict(zip("IVXLCDM",[1,5,10,50,100,500,1000]))
while 1:
    try:
        ans = 0; n = 0;
        s = raw_input();
        for i in xrange(len(s)-1):
            n += R[s[i]]
            if R[s[i]]<R[s[i+1]]:
                ans -= n; n = 0;
            elif R[s[i]]>R[s[i+1]]:
                ans += n; n = 0;
        ans += n + R[s[len(s)-1]]
        print ans
    except EOFError:
        break

Submission status: Accepted

Solution code:
#!/usr/bin/python
#compat with both Py2/Py3
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

Submission status: Accepted

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

while True:
    try:
        roman = raw_input()
        sum = 0
        for i in range(len(roman)):
            sum += dict[roman[i]]
        sum -= 2*roman.count("IV")
        sum -= 2*roman.count("IX")
        sum -= 20*roman.count("XL")
        sum -= 20*roman.count("XC")
        sum -= 200*roman.count("CD")
        sum -= 200*roman.count("CM")
        print sum
    except:
        break

Submission status: Accepted

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

while True:
    try:
        roman = raw_input()
        sum = 0
        value = 1000
        for i in range(len(roman)):
            if value >= dict[roman[i]]:
                value = dict[roman[i]]
                sum += value
            else:
                sum -= 2*value
                value = dict[roman[i]]
                sum += value
        print sum
    except:
        break

Submission status: Accepted

Solution code:
import sys
roman={"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}

for s in sys.stdin:
    x=[]
    tmp = roman[s[0]]
    x.append(tmp)
    for c in s[1:-1]:
        tmp = roman[c]
        if x[-1]<tmp: x[-1] *= -1
        x.append(tmp)
    print sum(x)

Submission status: Accepted

Solution code:
import sys
roman={"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000}

for s in sys.stdin:
    x=[roman[s[0]]]
    for c in s[1:-1]:
        tmp = roman[c]
        if x[-1]<tmp: x[-1] *= -1
        x.append(tmp)
    print sum(x)

Submission status: Accepted

Solution code:
num_list = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}
s_list = {'IV':4, 'IX':9, 'XL':40, 'XC':90, 'CD':400, 'CM':900}

while True:
	try:
		num = raw_input()
		ans = 0
		for n in s_list:
			if n in num:
				num = num.replace(n, '')
				ans += s_list[n]
		res = list(num)
		for n in res:
			ans += num_list[n]
		print ans
	except:
		break

Submission status: Accepted

Solution code:
a = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
try:
    while True:
        s = raw_input()
        sm = a[s[-1]]
        for i in range(1, len(s)):
            if a[s[i - 1]] < a[s[i]]:
                sm -= a[s[i - 1]]
            else:
                sm += a[s[i - 1]]
        print sm
except EOFError:
    pass

Submission status: Accepted

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

while True:
  try:
    arr = list(raw_input())

    sum = 0
    for i in range(len(arr)):
      if i == (len(arr) - 1):
        sum += dict[arr[i]]
      else:
        a = dict[arr[i]]
        b = dict[arr[i+1]]
        if a >= b:
          sum += a
        else:
          sum -= a

    print sum
  except EOFError:
    break

Submission status: Accepted

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

while 1:
    try:
        roman = raw_input()
    except EOFError:
        break
    phase = 1000
    ret = 0
    cnt = 0
    for x in roman:
        cur = Roman[x]
        if cur < phase:
            ret += phase * cnt
            phase = cur
            cnt = 1
        elif cur == phase:
            cnt += 1
        elif cur > phase:
            ret += cur - cnt * phase
            phase = cur
            cnt = 0
    else:
        ret += phase * cnt
    print ret

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
while True:
    try:
        k = input()
        ad = 0

        if ('IV' in k) or ('IX' in k) or ('IL' in k) or ('IC' in k) or ('ID' in k) or ('IM' in k):
            ad += 2

        if ('VX' in k) or ('VL' in k) or ('VC' in k) or ('VD' in k) or ('VM' in k):
            ad += 10

        if ('XL' in k) or ('XC' in k) or ('XD' in k) or ('XM' in k):
            ad += 20

        if ('LC' in k) or ('LD' in k) or ('LM' in k):
            ad += 100

        if ('CD' in k) or ('CM' in k):
            ad += 200

        if 'DM' in k:
            ad += 1000

        s = list(k)

        for i in range(len(s)):
            if s[i] == 'I':
                s[i] = 1
            elif s[i] == 'V':
                s[i] = 5
            elif s[i] == 'X':
                s[i] = 10
            elif s[i] == 'L':
                s[i] = 50
            elif s[i] == 'C':
                s[i] = 100
            elif s[i] == 'D':
                s[i] = 500
            else:
                s[i] = 1000

        print(sum(s) - ad)


    except EOFError:
        break

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

while 1:
    try:
        s = [t[i] for i in input()]
    except:
        break
    i = 0
    while i < len(s) - 1:
        if s[i] < s[i + 1]:
            s[i + 1] = s[i + 1] - s[i]
            s.pop(i)
        i += 1
    print(sum(s))

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans
    
    ### intチェック
    def is_integer(self, n):
        try:
            float(n)
        except ValueError:
            return False
        else:
            return float(n).is_integer()

    ### 幾何学問題用
    def dist(self, A, B):
        d = 0
        for i in range(len(A)):
            d += (A[i]-B[i])**2            
        d = d**(1/2)
        return d

    ### 絶対値
    def abs(self, n):
        if n >= 0:
            return n
        else:
            return -n   

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

def printA(A):
    N = len(A)
    for i, n in enumerate(A):
        print(n, end='')
        if i != N-1:
            print(' ', end='')
    print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート（代入する必要なし）
# N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
            #N.append([int(x) for x in input().split()])
        except EOFError:
            break
    return N

D = get_input()

for S in D:
    ans = 0
    temp = ''
    for s in S:
        if s == 'I':
            ans += 1
        elif s == 'V':
            if temp == 'I':
                ans += 3
            else:
                ans += 5
        elif s == 'X':
            if temp == 'I':
                ans += 8
            else:
                ans += 10
        elif s == 'L':
            if temp == 'X':
                ans += 30
            else:
                ans += 50
        elif s == 'C':
            if temp == 'X':
                ans += 80
            else:
                ans += 100
        elif s == 'D':
            if temp == 'C':
                ans += 300
            else:
                ans += 500
        elif s == 'M':
            if temp == 'C':
                ans += 800
            else:
                ans += 1000
        temp = s
    print(ans)

Submission status: Accepted

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

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

while True:
	try:
		p = list(input())
	except EOFError:
		break
	ans = i = 0
	while i < len(p):
		if i+1 < len(p) and roman[p[i]] < roman[p[i+1]]:
			ans += roman[p[i+1]] - roman[p[i]]
			i += 1
		else: ans += roman[p[i]]
		i += 1
	print(ans)
"""

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
while True:
  try:
    n=input()
    count=0
    for i in range(len(n)):
      if i==int(len(n))-1:
        if n[i]=="I":
          count+=1
        elif n[i]=="V":
          count+=5
        elif n[i]=="X":
          count+=10
        elif n[i]=="L":
          count+=50
        elif n[i]=="C":
          count+=100
        elif n[i]=="D":
          count+=500
        elif n[i]=="M":
          count+=1000
      elif n[i]=="I":
        if n[i+1]!="I":
          count-=1
        else:
          count+=1
      elif n[i]=="V":
        if n[i+1]!="I" and n[i+1]!="V":
          count-=5
        else:
          count+=5
      elif n[i]=="X":
        if n[i+1]=="L" or n[i+1]=="C" or n[i+1]=="D" or n[i+1]=="M":
          count-=10
        else:
          count+=10
      elif n[i]=="L":
        if n[i+1]=="C" or n[i+1]=="D" or n[i+1]=="M":
          count-=50
        else:
          count+=50
      elif n[i]=="C":
        if n[i+1]=="D" or n[i+1]=="M":
          count-=100
        else:
          count+=100
      elif n[i]=="D":
        if n[i+1]=="M":
          count-=500
        else:
          count+=500
      elif n[i]=="M":
        count+=1000
    print(count)
  except EOFError:
    break

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
def translation(string):
    roman = {'I': 1, 'V': 5, 'X': 10, 'L': 50,
             'C': 100, 'D': 500, 'M': 1000 }
    ans = 0
    for i in range(len(string)):
        if i == len(string)-1 or \
            roman[string[i]] >= roman[string[i+1]]:
            ans += roman[string[i]] * 1
        else:
            ans += roman[string[i]] * -1
    return ans

while True:
    try: start = input()
    except: break
    
    ans = translation(start)
    print(ans)

Submission status: Accepted

Solution code:
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()

Submission status: Runtime Error

Solution code:
def brain(l):
    c = l[1] - l[0]
    if 0 < c:
        result.append(c)
        del lis[0]
        del lis[0]
    else:
        lis.append(l[0])
        del lis[0]
        
def cisco(l):
    for i in range(len(l)):
        if l[i] == 'I':
            l[i] = 1
        elif l[i] == 'V':
            l[i] = 5
        elif l[i] == 'X':
            l[i] = 10
        elif l[i] == 'L':
            l[i] = 50
        elif l[i] == 'C':
            l[i] = 100
        elif l[i] == 'D':
            l[i] = 500
        elif l[i] == 'M':
            l[i] = 1000
    return l

while True:
    result = []
    try:
        lis = list(raw_input())+['*']
        while lis:
            if not (lis[0] == '*' or lis[1] == '*'):
                l = cisco([lis[0], lis[1]])
                brain(l)
            else:
                lis.append(lis[0])
                del lis[0]
                del lis[0]
                break
        result.append(sum(cisco(lis)))
        print sum(result)
    except EOFError:
        break

Submission status: Runtime Error

Solution code:
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))

Submission status: Runtime Error

Solution code:
#encoding=utf-8
import sys

def inp():
    for line in sys.stdin:
        word = line.split()
        je(word[0])

def je(word):
    ans, i = 0, 0
    while True:
        print word[i], ans
        if word[i] == "M":
            ans += 1000
        elif word[i] == "D":
            ans += 500
        elif word[i] == "C":
            ans += 100
            try:
                if word[i + 1] == "D":
                    ans += 300
                    i += 1
                elif word[i + 1] == "M":
                    ans += 800
                    i += 1
            except:pass
        elif word[i] == "L":
            ans += 50
            try:
                if word[i - 1] == "X":
                    ans -= 10
                    i += 1
            except: pass
        elif word[i] == "X":
            ans += 10
            try:
                if word[i + 1] == "I" and word[i + 2] == "X":
                    ans += 9
                    i += 2
                elif word[i + 1] == "C":
                    ans += 80
                    i += 1

            except: pass
        elif word[i] == "V":
            ans += 5
        elif word[i] == "I":
            ans += 1
            try:
                if word[i + 1] == "V":
                    ans += 4
                    i += 1
                if word[i + 1] == "X":
                    ans += 8
                    i += 1
            except: pass
        i += 1
        if i == len(word):
            print ans
            break

if __name__ == "__main__":
    inp()

Submission status: Runtime Error

Solution code:
import sys

def inp():
    for line in sys.stdin:
        word = line.split()
        je(word[0])

def je(word):
    ans, i = 0, 0
    while True:
        if word[i] == "M":
            ans += 1000
        elif word[i] == "D":
            ans += 500
        elif word[i] == "C":
            ans += 100
            try:
                if word[i + 1] == "D":
                    ans += 300
                    i += 1
                elif word[i + 1] == "M":
                    ans += 800
                    i += 1
            except:pass
        elif word[i] == "L":
            ans += 50
            try:
                if word[i - 1] == "X":
                    ans -= 10
                    i += 1
            except: pass
        elif word[i] == "X":
            ans += 10
            try:
                if word[i + 1] == "I" and word[i + 2] == "X":
                    ans += 9
                    i += 2
                elif word[i + 1] == "C":
                    ans += 80
                    i += 1

            except: pass
        elif word[i] == "V":
            ans += 5
        elif word[i] == "I":
            ans += 1
            try:
                if word[i + 1] == "V":
                    ans += 4
                    i += 1
                if word[i + 1] == "X":
                    ans += 8
                    i += 1
            except: pass
        i += 1
        if i == len(word):
            print ans
            break

if __name__ == "__main__":
    inp()

Submission status: Runtime Error

Solution code:
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(len(s)):
        if num[s[i-1]]<num[s[i]]:
            ans+=num[s[i]]-2*num[s[i-1]]
        else:
            ans+=num[s[i]]
    print(ans)

Submission status: Runtime Error

Solution code:
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 num[s[i-1]]<num[s[i]]:
            ans+=num[s[i]]-2*num[s[i-1]]
        else:
            ans+=num[s[i]]
    print(ans)

Submission status: Runtime Error

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

while True:
    try:
        roman = raw_input()
        sum = 0
        value = 1000
        for i in range(len(roman)):
            if value >= dict[roman[i]]:
                value = dict[roman[i]]
                sum += value
            elif:
                sum -= 2*value
                value = dict[roman[i]]
                sum += value
        print sum
    except:
        break

Submission status: Runtime Error

Solution code:
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))