x = {1: 'I', 5: 'V', 10: 'X', 50: 'L', 100: 'C', 500: 'D', 1000: 'M'}
rome_num = 'IIIIVIIIIX' + 'XXXXLXXXXC' + 'CCCCDCCCCM'
aa = ''
a = 998
for i in range(len(str(a)), 0, -1):
b = a // 10 ** (i - 1)
a = a % 10 ** (i - 1)
if b < 4 or (b > 5 and b < 9):
aa += rome_num[b // 5 * 4 + 10 * (i - 1):b + 10 * (i - 1)]
else:
aa += rome_num[b - 1 + 10 * (i - 1):b // 6 * 5 + 5 + 10 * (i - 1)]
print(aa)
x = dict((value, key) for (key, value) in x.items())