#include #include #include using namespace std; const string c = "IVXLCDM"; int cn[] = {1, 5, 10, 50, 100, 500, 1000}; const vector dc = {"IV", "IX", "XL", "XC", "CD", "CM"}; int dcn[] = {4, 9, 40, 90, 400, 900}; int dec(const string &r){ int res = 0; for(int i = 0; i < r.length(); i++){ bool added = false; for(int j = 0; j < 6; j++){ if(r.substr(i, 2) == dc[j]){ res += dcn[j]; added = true; i++; } } if(added) continue; for(int j = 0; j < 7; j++){ if(r[i] == c[j]){ res += cn[j]; } } } return res; } int main(){ int n; cin >> n; int total = 0; while(n--){ string r; cin >> r; total += dec(r); } if(total >= 4000) cout << "ERROR" << endl; else{ string ans = ""; if(total >= 1000){ for(int i = 0; i < total/1000; i++) ans += "M"; } total %= 1000; if(total >= 900) ans += "CM"; else if(total >= 500){ ans += "D"; total -= 500; for(int i = 0; i < total/100; i++) ans += "C"; }else if(total >= 400) ans += "CD"; else{ for(int i = 0; i < total/100; i++) ans += "C"; } total %= 100; if(total >= 90) ans += "XC"; else if(total >= 50){ ans += "L"; total -= 50; for(int i = 0; i < total/10; i++) ans += "X"; }else if(total >= 40) ans += "XL"; else{ for(int i = 0; i < total/10; i++) ans += "X"; } total %= 10; if(total >= 9) ans += "IX"; else if(total >= 5){ ans += "V"; total -= 5; for(int i = 0; i < total; i++) ans += "I"; }else if(total >= 4) ans += "IV"; else{ for(int i = 0; i < total; i++) ans += "I"; } cout << ans << endl; } return 0; }