Roman Cities
A well-known software development company has been commissioned by the Archaeological Society. One of the modules has to help the archaeologists to process data about the ruins of buildings they have found during their excavations of ancient cities. Development of this module has been assigned to Vasya.
Vasya, being a seasoned programmer, at once noticed that the module would need a database to contain the descriptions of the ruins and the estimated construction times of the buildings. It would be all fine, but suddenly the manager got the genial idea that since the database describes Roman ruins, the years of construction should be stored in the Roman number system. Now Vasya is wondering how many symbols he needs to set aside for each year number field in the database. According to the functional specification, the software module must be able to handle years from A to B (inclusive). Help Vasya determine the minimal number of characters sufficient for storing any year number in the range from A to B.
Input
he only input line contains the descriptions of the years A and B, separated by the "-". sign. A description of a year consists of one to four decimal digits (the number of the year), followed by either AD (Anno Domini, the current era) or BC (Before Christ, before the current era). In both directions the years are numbered starting from 1. It is known that 753BС ≤ A ≤ B ≤ 2012AD.
Output
The output should consist of a single integer, the minimal number of characters that have to be reserved in the database for the year number.
Examples
Note
It is well known that the Roman number system uses the following seven letters for digits: I - 1, V - 5, X - 10, L - 50, C - 100, D - 500 and M - 1000. Natural numbers are written by repeating these digits. For correct representation of a larger integer in the Roman system, first the thousands, then the hundreds, then the tens and finally the ones are written. In any of the positions, some digits (I, X, C, M) may be repeated, but no more than three times. If in any position a digit with lower or equal value is to the right of a digit of higher value, the lower value is added to the higher one. Only I, X, C and M may be added and there may be no more than three equal-valued digits in any position. If, however, a digit with lower value is to the left of a digit with higher value, the lower value is subtracted from the higher one. There are only six subtractions allowed: IV - 4, IX - 9, XL - 40, XC - 90, CD - 400 and CM - 900. Any other combinations are not allowed. So, for example, 99 has to be written as XCIX, not as IC.
It is also important to remember that the Romans did not use the AD/BC concepts. Instead, they counted the years from the mythical founding of Rome (Anno Urbis Conditae - 753BC).
Some examples of Roman year numbers:
753 BC - 1 AUC - I
1 BC - 753 AUC - DCCLIII
1 AD - 754 AUC - DCCLIV
2012 AD - 2765 AUC - MMDCCLXV