program dwiteq4;
uses crt;

function add(input:string):integer;
begin
     if (input='I') then
        add:=1;
     if (input='V') then
        add:=5;
     if (input='X') then
        add:=10;
     if (input='L') then
        add:=50;
     if (input='C') then
        add:=100;
     if (input='D') then
        add:=500;
     if (input='M') then
        add:=1000;
end;

var infile, outfile: text;
    input:string;
    sum,x,icount:integer;

begin
clrscr;
     {$I-}
     assign (outfile, 'OUT4.txt');
     reset (outfile);

     assign(infile, 'DATA4.txt');
     reset (infile);

     if IOResult=2 then
     begin
          rewrite (outfile);
     end;

     for icount:= 1 to 5 do
     begin
          readln(infile, input);
          sum:=0;
          for x:=1 to length(input) do
          begin
               if ((add(input[x])<(add(input[x+1]))) and (x<>length(input))) then
               begin
                    sum:=sum+add(input[x+1])-add(input[x]);
                    x:=x+1;
               end
               else
               begin
                    sum:=sum+add(input[x]);
               end;
          end;
          writeln(outfile, sum);

     end;

close (outfile);
close (infile);
readln;
end.












