#include #define rep(i, a, n) for(int i = a; i < n; i++) using namespace std; typedef pair P; const int INF = 1e8; int d[7] = {1, 5, 10, 50, 100, 500, 1000}; string str = "IVXLCDM"; int change_10(string s){ int res = 0; int now, pre = INF; rep(i, 0, s.size()){ int id = str.find(s[i]); now = d[id]; if(pre < now){ res += now - pre; pre = INF; }else{ if(pre != INF) res += pre; pre = now; } } if(pre != INF) res += pre; return res; } string change_roman(int n){ string res = ""; for(int i = str.size() - 1; i >= 0; i--){ int tmp = n / d[i]; n -= d[i] * tmp; if(tmp == 4){ res += str[i]; res += str[i + 1]; }else{ for(int j = 0; j < tmp; j++) res += str[i]; } } return res; } int main(){ int n; cin >> n; int sum = 0; for(int i = 0; i < n; i++){ string s; cin >> s; int tmp = change_10(s); sum += tmp; } if(sum >= 4000){ cout << "ERROR" << endl; return 0; } string ans = change_roman(sum); cout << ans << endl; }