Roman numerals#2552

Roman numerals

1 second
64 megabytes
Very hard

Roman numerals are based on seven symbols: "I", "V", "X", "L", "C", "D" and "M". The values of these symbols are , , , , , , and , respectively. To calculate the decimal value of a Roman numeral, use the following algorithm:

  1. Find the most significant ("most valuable") symbol. If there are multiple such symbols, choose the leftmost one. Let this symbol be at position i.

  2. Denote as Middle the value of the symbol at position i.

  3. Calculate the value of the Roman numeral formed by the symbols to the right of i. Denote this value as Right.

  4. Calculate the value of the Roman numeral formed by the symbols to the left of i. Denote this value as Left.

  5. The value of the Roman numeral is Middle + Right – Left. It is clear that, using this algorithm, the same number can be written in many ways. For example, the number can be written as "IXX", "XIX", "XVIV", "XVIIII", and so on.

Given a decimal number and a Roman numeral , find such a permutation of the symbols in that represents in Roman notation.

Input

The first line contains the integer in decimal notation. The second line contains the Roman numeral (-50000 \leq n \leq 50000, 1 \leq \text{length}(S) \leq 50).

Output

The first line of the output should contain the Roman numeral or the word "NO" (without quotes) if there is no solution.

Examples

Example 1

Loading
Loading