請不要抄
ex=''
end=0
v=0
o=0
i=0
j=0
ree=1
ans=0
temp1=[]
temp2=[]
num1=0
num2=0
while end==0:
k=input().split()
check=len(k)
if check==1:
end=1
break
elif k[1]==k[0]:
print("ZERO")
else:
a=list(k[0])
b=list(k[1])
z=len(a)
for i in range(0,z):
if a[i]=='I':
temp1.append(1)
elif a[i]=='V':
temp1.append(5)
elif a[i]=='X':
temp1.append(10)
elif a[i]=='L':
temp1.append(50)
elif a[i]=='C':
temp1.append(100)
elif a[i]=='D':
temp1.append(500)
elif a[i]=='M':
temp1.append(1000)
else:
continue
temp1.reverse()
num1+=int(temp1[0])
for v in range(1,z):
if int(temp1[v])<int(temp1[v-1]):
ree=-1
else:
ree=1
num1+=ree*int(temp1[v])
y=len(b)
for j in range(0,y):
if b[j]=='I':
temp2.append(1)
elif b[j]=='V':
temp2.append(5)
elif b[j]=='X':
temp2.append(10)
elif b[j]=='L':
temp2.append(50)
elif b[j]=='C':
temp2.append(100)
elif b[j]=='D':
temp2.append(500)
elif b[j]=='M':
temp2.append(1000)
else:
continue
temp2.reverse()
num2+=int(temp2[0])
for o in range(1,y):
if int(temp2[o])<int(temp2[o-1]):
ree=-1
else:
ree=1
num2+=ree*int(temp2[o])
bare=abs(num1-num2)
ans=bare//1000
ex+='M'*ans
bare=bare-1000*ans
if bare//100==9:
ex+='CM'
bare=bare-900
elif bare//100==4:
ex+='CD'
bare=bare-400
elif bare//100>=5:
bare=bare-500
ex+='D'
ans=bare//100
ex+='C'*ans
bare=bare-100*ans
else:
ans=bare//100
bare=bare-100*ans
ex+='C'*ans
if bare//10==9:
ex+='XC'
bare=bare-90
elif bare//10==4:
ex+='XL'
bare=bare-40
elif bare//10>=5:
bare=bare-50
ex+='L'
ans=bare//10
ex+='X'*ans
bare=bare-10*ans
else:
ans=bare//10
bare=bare-10*ans
ex+='X'*ans
if bare//1==9:
ex+='IX'
bare=bare-9
elif bare//1==4:
ex+='IV'
bare=bare-4
elif bare//1>=5:
bare=bare-5
ex+='V'
ans=bare//1
ex+='I'*ans
bare=bare-1*ans
else:
ans=bare//1
bare=bare-1*ans
ex+='I'*ans
print(ex)
ex=''
bare=0
ans=0
num1=0
num2=0