import java.util.*;
public class Solution {
    Map<Integer, String> map;
    String resr = "";
    public String ArabicToRoman (int n) {
        map = new HashMap<>();
        map.put(1, "I");
        map.put(4, "IV");
        map.put(5, "V");
        map.put(9, "IX");
        map.put(10, "X");
        map.put(40, "XL");
        map.put(50, "L");
        map.put(90, "XC");
        map.put(100, "C");
        map.put(400, "CD");
        map.put(500, "D");
        map.put(900, "CM");
        map.put(1000, "M");
        int arry[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
        func("", n, arry, 0);
        return resr;
    }
    void func(String res, int num, int[] array, int index) {
        if(resr != "")return;
        if(index >= array.length)return;
        if(num == 0) {
            resr = res;
            return;
        }
        for(int i = index; i < array.length; ++i) {
            if(num - array[i] < 0) continue;
            else func(res + map.get(array[i]), num - array[i], array, i);
        }
    }
}