#include<iostream>
#include<fstream>
#include<string>

using namespace std;

int sum(string firstLine){
    bool iIsPast = false;
    bool vIsPast = false;
    bool xIsPast = false;
    bool lIsPast = false;
    bool cIsPast = false;
    bool dIsPast = false;
    int sumA = 0;

    for(int x =firstLine.size() - 1;x>=0; x--){//first line
        if(firstLine[x] == 'I' && iIsPast==false){
            sumA+=1;

        }
        else if(firstLine[x]=='V'&& vIsPast==false){
            sumA+=5;
            iIsPast=true;

        }
        else if(firstLine[x]=='X'&& xIsPast==false){
            sumA+=10;
            vIsPast=true;
            iIsPast=true;

        }
        else if(firstLine[x]=='L'&& lIsPast==false){
            sumA+=50;
            xIsPast=true;
            vIsPast=true;
            iIsPast=true;

        }
        else if(firstLine[x]=='C'&& cIsPast==false){
            sumA+=100;
            lIsPast=true;
            xIsPast=true;
            vIsPast=true;
            iIsPast=true;

        }
        else if(firstLine[x]=='D'&& dIsPast==false){
            sumA+=500;
            cIsPast=true;
            lIsPast=true;
            xIsPast=true;
            vIsPast=true;
            iIsPast=true;

        }
        else if(firstLine[x]=='M'){
            sumA+=1000;
            dIsPast=true;
            cIsPast=true;
            lIsPast=true;
            xIsPast=true;
            vIsPast=true;
            iIsPast=true;

        }
        else if(firstLine[x] == 'I' && iIsPast==true){
            sumA-=1;

        }
        else if(firstLine[x]=='V'&& vIsPast==true){
            sumA-=5;

        }
        else if(firstLine[x]=='X'&& xIsPast==true){
            sumA-=10;

        }
        else if(firstLine[x]=='L'&& lIsPast==true){
            sumA-=50;

        }
        else if(firstLine[x]=='C'&& cIsPast==true){
            sumA-=100;

        }
        else if(firstLine[x]=='D'&& dIsPast==true){
            sumA-=500;

        }

    }

    return sumA;

}




int main(){
    string firstLine;
    string secondLine;
    string thirdLine;
    string fourthLine;
    string fifthLine;
    int sum1,sum2,sum3,sum4,sum5;


    ifstream fin("DATA4.txt");
    ofstream fout ("OUT4.txt");

    fin>> firstLine;
    fin>>secondLine;
    fin>>thirdLine;
    fin>>fourthLine;
    fin>>fifthLine;

    sum1=sum(firstLine);
    sum2=sum(secondLine);
    sum3=sum(thirdLine);
    sum4=sum(fourthLine);
    sum5=sum(fifthLine);

    fout<<sum1<<endl;
    fout<<sum2<<endl;
    fout<<sum3<<endl;
    fout<<sum4<<endl;
    fout<<sum5<<endl;




    return 0;





}

