program i; const s: array [1..7] of char = ('I', 'V', 'X', 'L', 'C', 'D', 'M'); ceny: array [1..7] of integer = (1, 5, 10, 50, 100, 500, 1000); var a: array [1..10000] of char; poc: integer; function hod(c: char): integer; var i: integer; begin for i:=1 to 7 do if upcase(c) = s[i] then begin hod:=ceny[i]; exit; end; hod:=0; end; var c: char; total, cena: integer; last: char; count: integer; begin count := 0; while not eof(input) do begin poc := 0; total :=0; last := #0; while not eoln(input) do begin read(c); cena := hod(c); if cena=0 then continue; if (cena=1) and (total mod 10>2) then continue; if (cena=10) and (total mod 100>20) then continue; if (cena=100) and (total mod 1000>200) then continue; if (cena=5) and (total mod 10>5) then continue; if (cena=50) and (total mod 100>50) then continue; if (cena=500) and (total mod 1000>500) then continue; total := total - (total mod cena) + cena; end; readln; writeln(total); inc(count); if count>10 then break; end; end.