#pragma GCC target("avx2") #pragma GCC optimize("03") #pragma GCC optimize("unroll-loops") #include using namespace std; typedef long double ld; typedef long long ll; typedef unsigned long long ull; #define endl "\n" #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define rep(i,n) for(int i=0;i<(n);i++) #define PII pair #define PLL pair #define ALL(x) (x).begin(), (x).end() constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1; templateinline bool chmax(T &a, const T &b) { if (ainline bool chmin(T &a, const T &b) { if (binline int popcount(T a) {return __builtin_popcount(a);} templateinline T emod(T a, T p) { return (a%p + p) % p;} //------------------- map mp = {{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}}; vector resi = {"CM", "CD", "XC", "XL", "IX", "IV"}; vector vv = {900, 400, 90, 40, 9, 4}; vector v = {'I', 'V', 'X', 'L', 'C', 'D', 'M'}; // vector resi = {} int rom2int() { string s; cin >> s; int sm = 0; rep(i, s.size()) { if(i < s.size()-1 and mp[s[i]] < mp[s[i+1]]) { sm -= mp[s[i]]; } else { sm += mp[s[i]]; } } return sm; } void int2rom(int k) { string s = ""; rep(i, v.size()) { int cur = k / mp[v[i]]; rep(_, cur) s += v[i]; k -= cur * mp[v[i]]; if(i < v.size()-1 and k >= vv[i]) { s += resi[i]; k -= vv[i]; } } cout << s << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); int n; cin >> n; reverse(ALL(v)); int sm = 0; rep(i, n) { sm += rom2int(); } // cout << sm << endl; // int sm = 4; if(sm >= 4000) cout << "ERROR" << endl; else { int2rom(sm); } return 0; }