using System; namespace No._518 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] roma = Console.ReadLine().Split(); Program program = new Program(); int sum = 0; for (int i = 0; i < N; i++) { sum += program.CharToNum(roma[i].ToCharArray()); } string ans = program.NumToChar(sum); Console.WriteLine(ans); } public int CharToNum(char[] roma) { int result = 0; Array.Reverse(roma); for (int i = 0; i < roma.Length; i++) { switch (roma[i]) { case 'M': result += 1000; break; case 'D': result += 500; break; case 'C': if (i != 0) { if (roma[i - 1] == 'M' || roma[i - 1] == 'D') { result -= 100; break; } } result += 100; break; case 'L': result += 50; break; case 'X': if (i != 0) { if (roma[i - 1] == 'L' || roma[i - 1] == 'C') { result -= 10; break; } } result += 10; break; case 'V': result += 5; break; case 'I': if (i != 0) { if (roma[i - 1] == 'V' || roma[i - 1] == 'X') { result -= 1; break; } } result += 1; break; } } return result; } public string NumToChar(int number) { if (number > 3999) { return "ERROR"; } string result = ""; if (number >= 1000) { int n = number / 1000; number %= 1000; while (n > 0) { result += "M"; n--; } } if (number >= 100) { int n = number / 100; number %= 100; if (n == 9) { result += "CM"; n -= 9; } else if (8 >= n && n >= 5) { result += "D"; n -= 5; } else if (n == 4) { result += "CD"; n -= 4; } while (n > 0) { result += "C"; n--; } } if (number >= 10) { int n = number / 10; number %= 10; if (n == 9) { result += "XC"; n -= 9; } else if (8 >= n && n >= 5) { result += "L"; n -= 5; } else if (n == 4) { result += "XL"; n -= 4; } while (n > 0) { result += "X"; n--; } } if (number >= 1) { if (number == 9) { result += "IX"; number -= 9; } else if (8 >= number && number >= 5) { result += "V"; number -= 5; } else if (number == 4) { result += "IV"; number -= 4; } while (number > 0) { result += "I"; number--; } } return result; } } }