import java.util.*;
public class Solution {

    //these have to be descending order

    


    enum NUMERALS
    {
        //M=1000, C=100, D=500, L=50, X=10,  V=5,  I=1
        1000("M"), 500("D"), 100("C"), 50("L"), 10("X"), 5("V"),1("X");

        int numeral;

        public NUMERALS (String romanNumeral)
        {
            this.numeral=numeral;
        }
    }


//irrelevant which order since it will be exact discrete remainder
enum REMAINDER
    {
        4("IV"), 9("IX"), 40("XL"), 90("XC"), 400("CD"),900("CM");

        int remainder;

        public REMAINDER (String romanNumeral)
        {
            this.remainder=remainder;
        }
    }

    //NUMERALS numeral = NUMERAL.1000.value();

    static int remainingNumber;
    
    static int counter=1;

    //this will be remainder once it passes through the switch statement


    public static String decimalToRoman(int num) {
        //return "test";

        //I will first attempt this from recursive perspective..
        //using a class level variable

        //This should much easier than conversion numeral => decimal number

        //we only need to worry about the valid subtractive notations (as a pair)
        
        //do not need to worry about adjacent subtractive notation being in the same range

        //not relevant
        i.e  IX XC
             range (1-10)  (range 10-100)

        // these are the valid combinations....

        //String IV =  "IV";
        //String IX =  "IX";
        //String XL =  "XL";
        //String XC =  "XC";
        //String CD=   "CD"; 
        //String CM=   "CM";

        //Also need to consider this rule
        The xcletters V, L, and D are not repeated.


        //I will work this example using the following two numbers
        //27  and also 19
        //both will bring their own challenges

        do
        {
        //main structure of code
        if (Integer.valueOf(remainingNumber==0))
        {

        return conversion;
        }

        
        else
        {
            
            //M=1000, C=100, D=500, L=50, X=10,  V=5,  I=1
            
            for (enum m: NUMERALS.values())
            {
                if (num-Integer.valueOf(m)>0)
                {

                    currentNumeral++;

                    //this should be suitable where there are no subtractive notations such as 27

                     //we know with examples such as 19
                    //it will pick off the X=10
                    //remainder will be 9
                    // it will then perform VIIII
                    //we know infact it should be getting IX

                    //decision making has to change
                    //ultimately we are checking if the remainder evaluates to any of these in REMAINDER enum

                    conversion = conversion + String.valueOf(m.value());

                    
                    char lastNumeralInConversion;
                    int lengthConversion = conversion.length();


                    if (conversion.length()>=4)

                    {
                    
                    do
                    {
                        counter++;

                
                //since the conversion string is geting shorter,
                //the do while loop will ensure that it breaks out timely when counter==5


                if (conversion.charAt(lengthConversion-counter) == conversion.charAt(lengthConversion-1))
                {
                        //four in a row...
                        //now need to remove the four in a row
                        //also need to remove the one before in conversion...

                        //for instance
                        //94 might appear as

                        //94  
                        //-50    L
                        //-10    X
                        //-10    X
                        //-10    X
                        //-10    X

                        //need remove 5 numerals
                        //then place repeat numeral into the conversion.
                        //then place next highest enum
                        //to give  XC

                       char fourInRowNumeral = conversion.charAt(conversion.length()-1);
                       
                       // need to get rid of 5 rogue numerals...

                       conversion=conversion.substring(conversion,conversion.length()-5);
                        
                       conversion = conversion + fourInRowNumeral;

                        //now need to add next higher numeral
                        String nextHighestNumeral = NUMERALS.values()[currentNumeral-1];
                        conversion = conversion  +   nextHighestNumeral;
                       
                        //whereas XCIV is correct

                        }
                        
                    }while(counter<5);

                    //for 94 for instance//
                    //need to subtract   IIII

                    return (num-)

                    //fourInRow=false;
                    counter=0;

                }  //if the converted numeral so far is greater than or equal to 4

                   

                    for (enum t: REMAINDER.values)
                    {
                        if (num==Integer.valueOf(t))
                        {
                            conversion = conversion + String.valueOf(t);

                        //need to have a think about a roman numeral such as 44
                        //it has XL IV  
                        //two subtractive numerals....

                        //we are not focussed on entering invalid roman numerals by end user
                        //this was level of difficulty in numeral => decimal conversion

                        //we will discover that when it reaches the most outer
                        //enum, it find X and perform XXXX
                        //and then the inner enum will register  4 = IV and append this..
                        //it will give outcome such as XXXX IV
                        //alternatively it could give XXXX IIII
                        //
                        //instead of XLIV
                        //effectively we are seeing that in any scenario, the largest numeral could appear 4 times and then smaller numeral...
                        //so it is better to trap this scenario as such

                            return conversion;
                        }
                    }


                     //at this point return what is left                     

                    return decimalToRoman(num-Integer.valueOf(m));

                     }  //if (num-integer.valueOf(m)>0)
                    
                }
            }

        }while ((Integer.valueOf(conversion)-num)==0);

        return conversion;

    }
}