#include using namespace std; string dec2rome(int n) { if (n >= 1000) { return "M" + dec2rome(n - 1000); } else if (n >= 900) { return "CM" + dec2rome(n - 900); } else if (n >= 500) { return "D" + dec2rome(n - 500); } else if (n >= 400) { return "CD" + dec2rome(n - 400); } else if (n >= 100) { return "C" + dec2rome(n - 100); } else if (n >= 90) { return "XC" + dec2rome(n - 90); } else if (n >= 50) { return "L" + dec2rome(n - 50); } else if (n >= 40) { return "XL" + dec2rome(n - 40); } else if (n >= 10) { return "X" + dec2rome(n - 10); } else if (n >= 9) { return "IX" + dec2rome(n - 9); } else if (n >= 5) { return "V" + dec2rome(n - 5); } else if (n >= 4) { return "IV" + dec2rome(n - 4); } else if (n >= 1) { return "I" + dec2rome(n - 1); } else { return ""; } } int rome2dec(string s) { map m; m['I'] = 1; m['V'] = 5; m['X'] = 10; m['L'] = 50; m['C'] = 100; m['D'] = 500; m['M'] = 1000; int ans = 0, prev = 0; for (char c : s) { ans += m[c]; if (m[c] > prev) ans -= 2 * prev; prev = m[c]; } return ans; } int main() { int n, ans = 0; cin >> n; for (int i = 0; i < n; i++) { string r; cin >> r; ans += rome2dec(r); } if (ans >= 4000) { cout << "ERROR" << endl; return 0; } }