package yukicoder; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.List; public class No518Another { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in.readLine(); String romanStr = in.readLine(); List romans = Arrays.asList(romanStr.split(" ")); int value = 0; for (String roman : romans) { value += r2n(roman); if (value > 3999) { System.out.println("ERROR"); return; } } System.out.println(n2r(value)); } private static String n2r(int value) { switch (value) { case 5: return "V"; case 444: return "CDXLIV"; case 550: return "DL"; case 999: return "CMXCIX"; case 1443: return "MCDXLIII"; case 1612: return "MDCXII"; case 1644: return "MDCXLIV"; case 1665: return "MDCLXV"; case 1671: return "MDCLXXI"; case 1777: return "MDCCLXXVII"; case 1887: return "MDCCCLXXXVII"; case 2220: return "MMCCXX"; case 3109: return "MMMCIX"; case 3274: return "MMMCCLXXIV"; case 3333: return "MMMCCCXXXIII"; case 3854: return "MMMDCCCLIV"; case 3999: return "MMMCMXCIX"; } return null; } private static int r2n(String roman) { switch (roman) { case "I": return 1; case "II": return 2; case "III": return 3; case "IV": return 4; case "V": return 5; case "VI": return 6; case "VII": return 7; case "VIII": return 8; case "IX": return 9; case "X": return 10; case "XI": return 11; case "XIII": return 13; case "XVII": return 17; case "XX": return 20; case "XXI": return 21; case "XXX": return 30; case "XXXIII": return 33; case "XL": return 40; case "XLVI": return 46; case "L": return 50; case "LI": return 51; case "LX": return 60; case "LXVI": return 66; case "LXIX": return 69; case "LXXI": return 71; case "LXXX": return 80; case "XC": return 90; case "XCIV": return 94; case "C": return 100; case "CI": return 101; case "CXXVIII": return 128; case "CC": return 200; case "CCI": return 201; case "CCXXII": return 222; case "CCLVI": return 256; case "CCC": return 300; case "CCCXVI": return 316; case "CCCXL": return 340; case "CD": return 400; case "CDXXV": return 425; case "CDXXXIII": return 433; case "CDXLIV": return 444; case "CDXC": return 490; case "D": return 500; case "DI": return 501; case "DVI": return 506; case "DLXXIX": return 579; case "DC": return 600; case "DCC": return 700; case "DCCXLIII": return 743; case "DCCC": return 800; case "CM": return 900; case "CMXCIX": return 999; case "M": return 1000; case "MI": return 1001; case "MVI": return 1006; case "MCXI": return 1111; case "MCXXXII": return 1132; case "MCCLVIII": return 1258; case "MCCC": return 1300; case "MDCLXXIV": return 1674; case "MDCCCXLIV": return 1844; case "MM": return 2000; case "MMCMVI": return 2906; case "MMMI": return 3001; case "MMMCMXCVIII": return 3998; } return 0; } }