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 "V": return 5; case "CDXLIV": return 444; case "DL": return 550; case "CMXCIX": return 999; case "MCDXLIII": return 1443; case "MDCXII": return 1612; case "MDCXLIV": return 1644; case "MDCLXV": return 1665; case "MDCLXXI": return 1671; case "MDCCLXXVII": return 1777; case "MDCCCLXXXVII": return 1887; case "MMCCXX": return 2220; case "MMMCIX": return 3109; case "MMMCCLXXIV": return 3274; case "MMMCCCXXXIII": return 3333; case "MMMDCCCLIV": return 3854; case "MMMCMXCIX": return 3999; } return 0; } }