//#define LOCAL #include #include #include #include #include #include #include #include #define int long long //typedef long long ll; #define rep(i, n) for(int i=0; i<(n); i++) using namespace std; int N; string R[105]; map mp; int romanToInt(string roman) { mp['I'] = 1; mp['V'] = 5; mp['X'] = 10; mp['L'] = 50; mp['C'] = 100; mp['D'] = 500; mp['M'] = 1000; int now = 0; int ret = 0; while (now < roman.length()) { string two = roman.substr(now, 2); if (two == "IV") { ret += 4; now += 2; } else if (two == "IX") { ret += 9; now += 2; } else if (two == "XL") { ret += 40; now += 2; } else if (two == "XC") { ret += 90; now += 2; } else if (two == "CD") { ret += 400; now += 2; } else if (two == "CM") { ret += 900; now += 2; } else { ret += mp[roman[now]]; now += 1; } } return ret; } void intToRoman(int num, char *roman) { int a[13]={1000,900,500,400,100,90,50,40,10,9,5,4,1}; char *r[13]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; roman[0]='\0'; for(int i=0;i<13;i++) { while(num>=a[i]){ strcat(roman,r[i]); num-=a[i]; } } } signed main() { #ifdef LOCAL ifstream in("input.txt"); cin.rdbuf(in.rdbuf()); #endif cin >> N; int ans = 0; rep(i, N) { cin >> R[i]; ans += romanToInt(R[i]); } if (ans > 3999) { cout << "ERROR" << endl; } else { char aaannss[50]; intToRoman(ans, aaannss); cout << aaannss << endl; } //cout << romanToInt("CCCXL") << endl; }