#include <iostream>
#include <iomanip>
#include <fstream>
#include <math.h>
#include <string>
#include <strings.h>
#include <vector>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <stdio.h>

#define fori(I) for (int i = 0; i < I; i++)
#define forj(J) for (int j = 0; j < J; j++)
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)

using namespace std;

char comp[] = "IVXLCDM";
int ret[] = {1, 5, 10, 50, 100, 500, 1000};

int converter(char c);

int main() {

    ifstream in ("DATA4.txt");  //DID YOU FIX THIS?
    ofstream out ("OUT4.txt");  //DID YOU FIX THIS?
    
    for (int Z = 0; Z < 5; Z++) {
        string str;
        in >> str;
        
        vector<int> arr;
        int total = 0;
        
        fori(str.size())
            arr.push_back(converter(str[i]));
        
        while(arr.size()){
            int temp = 0;
            int _temp = 0;
            int num_change = 1;
            
            fori(arr.size()){
                if(arr[i] > temp){
                    temp = arr[i];
                    _temp = i;
                }
            }
            int t_total = temp;
            
            for(int i = _temp - 1; i >= 0 && arr[i] < temp; i++){
                num_change ++;
                t_total -= arr[i];
            }
            
            total += t_total;
            arr.erase(arr.begin() + _temp + 1 - num_change, arr.begin() + _temp + 1);
        }
        
        out << total << endl;
    }
    
    //system("pause");            //REMOVE THIS BEFORE SUBMITTING
    return 0;
}

int converter(char c){
    fori(7){
        if(c == comp[i])
            return ret[i];
    }
    
    return 0;
}

