package yukicoder; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String roma = sc.nextLine(); roma = sc.nextLine(); int total = 0; String[] spl = roma.split(" "); for(int i = 0 ; i < spl.length ; i++){ int subTotal = 0; for(int j = 0 ; j < spl[i].length() ; j++){ int num = 0; switch(spl[i].charAt(j)){ case 'I' : num = 1; break; case 'V' : num = 5; break; case 'X' : num = 10; break; case 'L' : num = 50; break; case 'C' : num = 100; break; case 'D' : num = 500; break; case 'M' : num = 1000; break; } if(num > subTotal && subTotal !=0){ total += num - subTotal; subTotal = 0; }else{ total += subTotal; subTotal = num; } } total += subTotal; } int[] numArray = {1000,900,500,400,100,90,50,40,10,9,5,4,1}; String[] romaArray = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; int work = total; String disp = ""; for(int i = 0 ; i < numArray.length ; i++){ int work2 = work/numArray[i]; for(int j = 0 ; j < work2 ; j++){ disp+=romaArray[i]; } work %= numArray[i]; } if(total <= 3999){ System.out.println(disp); }else{ System.out.println("ERROR"); } } }