import copy n = int(input().strip()) nums = input().strip().split() pri_dic = {"DCCC":800,"LXXX":80,"VIII":8,"MMM":3000,"DCC":700,"CCC":300,"LXX":70,"XXX":30,"VII":7,"III":3,"MM":2000,"CM":900,"DC":600,"CD":400,"CC":200,"XC":90,"LX":60,"XL":40,"XX":20,"IX":9, "VI":6,"IV":4,"II":2,"M":1000,"D":500,"C":100,"L":50,"X":10,"V":5,"I":1} pri_lis = ["DCCC","LXXX","VIII"] pri_lis2 = ["MMM","DCC","CCC","LXX","XXX","VII","III"] pri_lis3 = ["MM","CM","DC","CD","CC","XC","LX","XL","XX","IX","VI","IV","II"] pri_lis4 = ["M","D","C","L","X","V","I"] def trans(x): lis = [] x2 = copy.deepcopy(x) for i in pri_lis: if x2[0:4] == i: lis.append(pri_dic[i]) x2 = x2[4:] for i in pri_lis2: if x2[0:3] == i: lis.append(pri_dic[i]) x2 = x2[3:] for i in pri_lis3: if x2[0:2] == i: lis.append(pri_dic[i]) x2 = x2[2:] for i in pri_lis4: if x2[0:1] == i: lis.append(pri_dic[i]) x2 = x2[1:] return sum(lis) nums2 = [] for i in range(n): nums2.append(trans(nums[i])) nums3 = sum(nums2) def get_key(va): return [k for k, v in pri_dic.items() if v == va][0] nums4 = [] def trans2(x): y = str(x) l = len(y) for i in range(l): a = y[-1-i] nums4.append(get_key(int(a)*(10**i))) nums5 = reversed(nums4) return ''.join(nums5) if nums3 <= 3999: print(trans2(nums3)) else: print("ERROR")