Under construction

Still being built. Things may change

IXth Problem

Time limit1sMemory limit1024 MB

Level

Not classified yet

Solved
No attempts yet

Problem

Emily recently learned about the Roman Empire and its civilization at school. One aspect she found especially interesting is the number system the Romans used, Roman numerals. The Roman numeral system uses seven distinct symbols, each with a different value and written as a letter: I is 11, V is 55, X is 1010, L is 5050, C is 100100, D is 500500, and M is 10001000. Multiples of 11, 1010, 100100, and 10001000 are written according to the following table:

×\times112233445566778899
11IIIIIIIVVVIVIIVIIIIX
1010XXXXXXXLLLXLXXLXXXXC
100100CCCCCCCDDDCDCCDCCCCM
10001000MMMMMM

Most entries in this table are formed additively, that is, by summing the values of the symbols. For example, LXX is 50+10+10=7050+10+10=70. The columns for 4 and 9, however, use subtractive notation: IV is read as 5−15-1, IX is read as 10−110-1, and so on.

Every number from 11 to 39993999 is written as a combination of entries from the table, using at most one entry from each row and going from bottom to top. For example, 20212021 is MMXXI and 594594 is DXCIV. Note that this number system cannot write numbers greater than 39993999, and subtractive notation is allowed only in the six cases above. For example, IC is not considered a valid Roman numeral.

Emily found a bunch of old Scrabble sets in her attic. She threw out all tiles with letters other than the Roman digits and started forming Roman numerals from the remaining tiles. It is easy to form valid numerals by using just one tile per Roman numeral, but what is the minimal number of numerals that can be formed while still using all the available tiles?

Input

The input consists of:

  • One line with seven integers m,d,c,ℓ,x,v,im,d,c,\ell,x,v,i (0≤m,d,c,ℓ,x,v,i≤10180 \le m,d,c,\ell,x,v,i \le 10^{18}), which are the numbers of M, D, C, L, X, V, and I tiles that must be used.

There is at least one tile, that is, m+d+c+ℓ+x+v+i≥1m+d+c+\ell+x+v+i \ge 1.

Output

Output an integer nn, the minimal possible number of Roman numerals that can be formed while using all tiles in the input. Then output an optimal solution in the following format.

  • An integer kk, the number of distinct Roman numerals used in this solution.
  • kk pairs of a Roman numeral and a positive integer indicating how many times this numeral is used in this solution.

The solution must consist of exactly nn numerals in total and must use exactly the specified number of each letter. The kk Roman numerals in the solution must be distinct. You do not need to minimize kk. If there is more than one optimal solution, any one of them is accepted.

Examples2

  1. Example 1

    Input
    4 1 7 1 3 1 3
    
    Expected output
    2
    2
    MMDCCCLXX 1
    MMCCCXCVIII 1
    
  2. Example 2

    Input
    0 0 0 300 2000 1000 2100
    
    Expected output
    1000
    2
    XXVIII 700
    LXXV 300