#include #define rep(i, a, n) for(int i = a; i < n; i++) #define repb(i, a, b) for(int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define o(a) cout << a << endl #define int long long #define fi first #define se second 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; } signed main(){ int n; cin >> n; int sum = 0; rep(i, 0, n){ string s; cin >> s; int tmp = change_10(s); sum += tmp; // cout << tmp << endl; } if(sum >= 4000){ cout << "ERROR" << endl; return 0; } string ans = ""; repb(i, 6, 0){ if(sum < d[i]) continue; int q = sum / d[i]; sum %= d[i]; // cout <