#include <bits/stdc++.h>
using namespace std;
int romanToInt(string s) {
map<char, int> m;
m['I'] = 1;
m['V'] = 5;
m['X'] = 10;
m['L'] = 50;
m['C'] = 100;
m['D'] = 500;
m['M'] = 1000;
int len = s.length();
if(len <= 0)
return 0;
int result = m[s[len - 1]];
for(int i = len - 2; i >= 0; i--){
if(m[s[i]] < m[s[i+1]]){
result = result - m[s[i]];
}else{
result = result + m[s[i]];
}
}
return result;
}
int main() {
cout << romanToInt("XIV");
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgcm9tYW5Ub0ludChzdHJpbmcgcykgewogICAgbWFwPGNoYXIsIGludD4gbTsKICAgIG1bJ0knXSA9IDE7CiAgICBtWydWJ10gPSA1OwogICAgbVsnWCddID0gMTA7CiAgICBtWydMJ10gPSA1MDsKICAgIG1bJ0MnXSA9IDEwMDsKICAgIG1bJ0QnXSA9IDUwMDsKICAgIG1bJ00nXSA9IDEwMDA7CiAgICBpbnQgbGVuID0gcy5sZW5ndGgoKTsKICAgIGlmKGxlbiA8PSAwKQogICAgICAgIHJldHVybiAwOwogICAgaW50IHJlc3VsdCA9IG1bc1tsZW4gLSAxXV07CiAgICBmb3IoaW50IGkgPSBsZW4gLSAyOyBpID49IDA7IGktLSl7CiAgICAgICAgaWYobVtzW2ldXSA8IG1bc1tpKzFdXSl7CiAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdCAtIG1bc1tpXV07CiAgICAgICAgfWVsc2V7CiAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdCArIG1bc1tpXV07CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIHJlc3VsdDsKfQoKaW50IG1haW4oKSB7Cgljb3V0IDw8IHJvbWFuVG9JbnQoIlhJViIpOwoJcmV0dXJuIDA7Cn0=