#include #include #include using namespace std; #define in(v) v; cin >> v; #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) #define rrep(i,n) for(int i=(n);i>=0;--i) int main() { int N; cin >> N; int ans = 0; char cur[5] = {'I', 'X', 'C', 'M', ' '}, mid[4] = {'V', 'L', 'D', ' '}; rep(i, N) { string in(a); int idx = 0; rrep(j, 3) { int k = idx; while (k < a.size() && (a[k] == cur[j] || a[k] == mid[j] || a[k] == cur[j+1])) ++k; string S = a.substr(idx, k-idx); idx = k; int n; if (S == string(1, cur[j]) + cur[j+1]) n = 9; else if (S == string(1, cur[j]) + mid[j]) n = 4; else if (S.find(mid[j]) == string::npos) n = S.length(); else n = S.length() + 4; ans += n * pow(10, j); } } if (ans > 3999) { cout << "ERROR\n"; return 0; } stack ans_s; rep(i, 4) { int n = ans % 10; ans /= 10; string s; if (n == 9) (s += cur[i]) += cur[i+1]; else if (n == 4) (s += cur[i]) += mid[i]; else { if (n >= 5) n -= 5, s += mid[i]; rep(k, n) s += cur[i]; } ans_s.push(s); } while (!ans_s.empty()) { cout << ans_s.top(); ans_s.pop(); } cout << endl; return 0; }