Miscalculation
Time limit1sMemory limit256 MB
Given a digit expression with + and * and Bob's answer, report whether it matches the precedence evaluation, the left-to-right evaluation, both, or neither.
- Level
Easy2 of 10
- Topics
- Simulation
- Solved
- No attempts yet
Problem
Bob is an elementary school student who is not good at mathematics. He found his father's calculator and used it to get through his homework. The homework was to evaluate expressions that mix multiplication and addition. Multiplication must be done before addition, but the calculator ignores operator precedence and evaluates the expression from left to right. So Bob's answer may come from either of the following two rules.
- Doing multiplication before addition
- Ignoring operator precedence and calculating from left to right
Given an expression and Bob's answer, decide which rule was applied.
An expression consists of integers and operators. Every integer is a single digit from 0 to 9. There are two operators, + for addition and * for multiplication.
For example, the expression 1+2*3+4 gives 11 under the multiplication-first rule and 13 under the left-to-right rule.
Both rules can give the same result, and then you cannot tell which one was applied. Bob also miscalculates sometimes. When neither rule gives Bob's answer, he made a mistake.
Input
The input is a single test case given on two lines. The first line contains the expression to evaluate. The number of characters in the expression is always odd and at most 17. Each odd-numbered character of the expression is a digit from 0 to 9, and each even-numbered character is the operator + or *. The second line contains an integer between 0 and 999999999, inclusive. This integer is Bob's answer for the expression on the first line.
Output
Print one of the following four characters.
M: only the multiplication-first rule gives Bob's answerL: only the left-to-right rule gives Bob's answerU: both rules give Bob's answerI: neither rule gives Bob's answer