using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { int MaxLimit = 3999; int itemCount = int.Parse(Reader.ReadLine()); string[] inpt = new string[itemCount]; inpt = Reader.ReadLine().Split(' '); int ans = 0; foreach (string roman in inpt) { ans += RomanToArabic(roman); } if (ans > MaxLimit) { Console.WriteLine("ERROR"); } else { Console.WriteLine(ans); } } private int RomanToArabic(string inpt) { int idx = -1; int ans = 0; while (++idx < inpt.Length) { if (idx < inpt.Length - 1) { if (Conv(inpt[idx]) < Conv(inpt[idx+1])) { ans += Conv(inpt[idx + 1]) - Conv(inpt[idx]); idx++; continue; } } ans += Conv(inpt[idx]); } return ans; } private int Conv(char c) { // I = 1、V = 5、X = 10、L = 50、C = 100、D = 500、M = 1000 switch (c) { case 'I': return 1; case 'V': return 5; case 'X': return 10; case 'L': return 50; case 'C': return 100; case 'D': return 500; default: return 1000; } } public class Reader { public static bool IsDebug = false; private static String PlainInput = @" 4 M M M M "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }