def roman2arabic(roman: str) -> int: special_case = { "IV" : 4, "IX" : 9, "XL" : 40, "XC" : 90, "CD" : 400, "CM" : 900 } normal_case = { "I" : 1, "V" : 5, "X" : 10, "L" : 50, "C" : 100, "D" : 500, "M" : 1000 } arabic = 0 for s in special_case.keys(): if s in roman: arabic += special_case[s] roman = roman.replace(s, "") for n in normal_case.keys(): if n in roman: arabic += roman.count(n) * normal_case[n] return arabic def arabic2roman(arabic: int) -> str: roman = "" while arabic > 0: if arabic >= 1000: roman += "M" arabic -= 1000 elif arabic >= 900: roman += "CM" arabic -= 900 elif arabic >= 500: roman += "D" arabic -= 500 elif arabic >= 100: roman += "C" arabic -= 100 elif arabic >= 90: roman += "XC" arabic -= 90 elif arabic >= 50: roman += "L" arabic -= 50 elif arabic >= 40: roman += "XL" arabic -= 40 elif arabic >= 10: roman += "X" arabic -= 10 elif arabic >= 9: roman += "IX" arabic -= 9 elif arabic >= 5: roman += "V" arabic -= 5 elif arabic >= 4: roman += "IV" arabic -= 4 else: roman += "I" arabic -= 1 return roman def solve(): n = input() ans = 0 for roman in input().split(): ans += roman2arabic(roman) if ans > 3999: print("ERROR") return # print(ans) ans_roman = arabic2roman(ans) print(ans_roman) if __name__=="__main__": solve()