using System;
using System.Collections.Generic;
using System.Text;
public class Program
{
public static void Main()
string str = "CD";
var list = new Dictionary<char,int>(){
{'I',1},{'V',5},{'X',10},{'L',50},{'C',100},{'D',500},{'M',1000}
};
int num = 0;
if(str.Length > 1){
for(int i=0; i<str.Length;i++){
var ch = str[i];
num = list[ch] + num;
if(i != 0)
var prevch = str[i-1];
if(list[ch] > list[prevch]){
num = num - (2*list[prevch]);
}
Console.WriteLine(num);