IXth Problem

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

Emily recently learned about the Roman Empire and its civilization at school. One aspect that was especially fascinating to her is the number system that they used, the Roman numerals. The Roman number system uses seven distinct digits, each representing a different value and denoted by a letter, where I is 11, V is 55, X is 1010, L is 5050, C is 100100, D is 500500 and M is 1,0001\\,000. Multiples of 11, 1010, 100100 and 1,0001\\,000 are then written according to the following table:

×\times112233445566778899
11IIIIIIIVVVIVIIVIIIIX
1010XXXXXXXLLLXLXXLXXXXC
100100CCCCCCCDDDCDCCDCCCCM
1,0001\\,000MMMMMM      

Most of the numerals in this table are formed additively, i.e. by summing the values of the digits. For example, LXX is 50+10+10=7050+10+10=70. Columns 44 and 99, however, use so-called subtractive notation, where IV is read as 515-1, IX is read as 10110-1, and so on.

Each number from 11 to 3,9993\\,999 is written as a combination of numerals from the table, using at most one numeral from each row and going from bottom to top. For instance, 2,0212\\,021 is MMXXI and 594594 is DXCIV. Note that in this number system it is not possible to write numbers greater than 3,9993\\,999 and also that subtractive notation can only be used in the six cases above (e.g. IC is not considered a valid Roman numeral).

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

입력

The input consists of:

  • One line with seven integers mm, dd, cc, \ell, xx, vv and ii (0m,d,c,,x,v,i10180 \le m,d,c,\ell,x,v,i \le 10^{18}), which respectively are the number 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+i1m+d+c+\ell+x+v+i \ge 1.

출력

Output an integer nn, the minimal possible number of Roman numerals that can be formed while using all of the 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 often 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 will be accepted.