#Lutece1664. Miscalculation
Miscalculation
Migrated from Lutece 1664 Miscalculation
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
is an elementary schoolboy, not so good at mathematics. He found Father’s calculator and tried cheating on his homework using it. His homework was calculating given expressions containing multiplications and additions. Multiplications should be done prior to additions, of course, but the calculator evaluates the expression from left to right, neglecting the operator precedence. So his answers may be the result of either of the following two calculation rules.
-
Doing multiplication before addition
-
Doing calculation from left to right neglecting the operator precedence
Write a program that tells which of the rules is applied from an expression and his answer.
An expression consists of integers and operators. All the integers have only one digit, from to . There are two kinds of operators and , which represent addition and multiplication, respectively.
The following is an example expression.
Calculating this expression with the multiplication-first rule, the answer is , as in Sample Input . With the left-to-right rule, however, the answer will be as shown in Sample Input .
There may be cases in which both rules lead to the same result and you cannot tell which of the rules is applied. Moreover, sometimes commits miscalculations. When neither rules would result in ’s answer, it is clear that he actually did.
Input
The input consists of a single test case specified with two lines. The first line contains the expression to be calculated. The number of characters of the expression is always odd and less than or equal to . Each of the odd-numbered characters in the expression is a digit from ‘’ to ‘’. Each of the even-numbered characters is an operator ‘’ or ‘’. The second line contains an integer which ranges from to , inclusive. This integer represents ’s answer for the expression given in the first line.
Output
Output one of the following four characters:
- When only the multiplication-first rule results ’s answer.
- When only the left-to-right rule results ’s answer.
- When both of the rules result ’s answer.
- When neither of the rules results ’s answer.
Samples
1+2*3+4
11
M
1+2*3+4
13
L
3
3
U
1+2*3+4
9
I
Resources
Japan > Asia Regional Contest 2014 in Tokyo Problem B