#P7773. Minimum Rearranged Roman Numeral

    ID: 20959 Type: Default 1000ms 256MiB

Minimum Rearranged Roman Numeral

Minimum Rearranged Roman Numeral

Given a Roman numeral \(B\), rearrange its characters to form the smallest possible valid Roman numeral.

You are provided with a string \(B\) consisting of the characters \(I, V, X, L, C, D, M\). The task is to reorder these characters such that the numerical value of the resulting numeral (when interpreted in standard Roman numeral notation) is minimized.

A valid Roman numeral must follow the standard rules including subtractive notation. For instance, although both VI and IV use the same characters \(I\) and \(V\), only IV represents the number 4 which is smaller than 6, the value of VI.

inputFormat

The input consists of a single line containing a string (B) -- a Roman numeral consisting solely of the characters {I, V, X, L, C, D, M}.

outputFormat

Output a single line: the smallest valid Roman numeral that can be obtained by rearranging the characters of (B). It is guaranteed that at least one valid rearrangement exists.

sample

VI
IV