main = interact $ unlines . map (show . roman_figure . map read_roman) . lines
read_roman r = case r of {'I'->1; 'V'->5; 'X'->10; 'L'->50; 'C'->100; 'D'->500; 'M'->1000}
roman_figure = sum . count
 where
  count (x:y:xys) = if x<y then y-x :(count xys) else x:y:(count xys)
  count xs = xs