Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Problem B:
Miscalculation

  Bob 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 0 to 9. There are two kinds of operators + and *, which represent addition and multiplication, respectively.

  The following is an example expression.

1+2*3+4

  Calculating this expression with the multiplication-first rule, the answer is 11, as in Sample Input 1. With the left-to-right rule, however, the answer will be 13 as shown in Sample Input 2.

  There may be cases in which both rules lead to the same result and you cannot tell which of the rules is applied. Moreover, Bob sometimes commits miscalculations. When neither rules would result in Bob’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 17. Each of the odd-numbered characters in the expression is a digit from '0' to '9'. Each of the even-numbered characters is an operator '+' or '*'. The second line contains an integer which ranges from 0 to 999999999, inclusive. This integer represents Bob's answer for the expression given in the first line.

Output

  Output one of the following four characters:

  

M     When only the multiplication-first rule results Bob's answer.

L     When only the left-to-right rule results Bob's answer.

U     When both of the rules result Bob's answer.

I     When neither of the rules results Bob's answer.

Sample Input 1

1+2*3+4
11

Sample Output 1

M

Sample Input 2

1+2*3+4
13

Sample Output 2

L

Sample Input 3

3
3

Sample Output 3

U

Sample Input 4

1+2*3+4
9

Sample Output 4

I



Sample input:
1+2*3+4
11


Sample output:
M

Submission status: Wrong Answer

Solution code:
s = raw_input()
a = int(raw_input())
print "IMLU"[int(eval(s) == a)+int(eval("("*s.count("*")+s.replace("*",")*"))== a)<<1]

Submission status: Accepted

Solution code:
s = input()
t = int(input())
e1 = eval(s)

e2 = int(s[0])
i = 1
while i < len(s):
    x = int(s[i+1])
    if s[i] == '+':
        e2 += x
    else:
        e2 *= x
    i += 2

if e1 == t and e2 == t:
    print("U")
elif e1 == t:
    print("M")
elif e2 == t:
    print("L")
else:
    print("I")

Submission status: Accepted

Solution code:
s,ans=input(),int(input())
x=int(s[0])
for i in range(1,len(s),2):
  y=int(s[i+1])
  x=x*y if s[i]=='*' else x+y
print("IMLU"[int(eval(s)==ans)+(int(x==ans)<<1)])

Submission status: Accepted

Solution code:
def lr_op(expr, length):
	op = {"+": lambda x,y : x + y, "*": lambda x,y : x * y }
	result = expr[0]
	inc = 1
	while inc < length:
		result = op[expr[inc]](result,expr[inc+1])
		inc += 2
	return result
inputs = raw_input()
length = len(inputs)
expr = [int(inputs[i]) if i % 2 == 0 else inputs[i] for i in range(length)]
bob = int(raw_input())
L = lr_op(expr, length)
inc = 1
while inc < length:
	if expr[inc] == "*":
		expr[inc] = expr[inc-1] * expr[inc+1]
		for i in range(2):
			del expr[inc-1+i]
		length -= 2
	else :
		inc += 2
M = lr_op(expr, length)
if M == bob:
	print "U" if L == bob else "M"
else :
	print "L" if L == bob else "I"

Submission status: Accepted

Solution code:
s = raw_input()
a = int(raw_input())
m = eval(s)
l = eval("("*s.count("*")+s.replace("*",")*"))
print "U" if a == m == l else "M" if a == m != l else "L" if a == l else "I"

Submission status: Accepted

Solution code:
s = raw_input()
a = int(raw_input())
m = eval(s)
l = eval("("*s.count("*")+s.replace("*",")*"))
print "U" if a == m == l else "M" if a == m else "L" if a == l else "I"

Submission status: Accepted

Solution code:
s = raw_input()
a = int(raw_input())
print "IMLU"[int(eval(s) == a)+int(eval("("*s.count("*")+s.replace("*",")*")) == a)*2]

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def solvM(e):
  p = [ 0 ]

  def term():
    res = 0
    while p[ 0 ] < len ( e ) and "0" <= e[ p[ 0 ] ] <= "9":
      res = res * 10 + ( ord ( e[ p[ 0 ] ] ) - ord ( "0" ) )
      p[ 0 ] = p[ 0 ] + 1
    return ( res )

  def fact():
    lv = term ( )
    while p[ 0 ] < len ( e ):
      if ( e[ p[ 0 ] ] == "*" ):
        p[ 0 ] = p[ 0 ] + 1
        lv = lv * term ( )
      else:
        break
    return ( lv )

  def expr():
    lv = fact ( )
    while p[ 0 ] < len ( e ):
      if ( e[ p[ 0 ] ] == "+" ):
        p[ 0 ] = p[ 0 ] + 1
        lv = lv + fact ( )
      else:
        break
    return ( lv )

  return expr ( )

def solvL(e):
  p = 0

  lv = 0
  while p < len ( e ) and "0" <= e[ p ] <= "9":
    lv = lv * 10 + ord ( e[ p ] ) - ord ( "0" )
    p = p + 1

  while p < len ( e ):
    op = e[ p ]
    p = p + 1

    rv = 0
    while p < len ( e ) and "0" <= e[ p ] <= "9":
      rv = rv * 10 + ord ( e[ p ] ) - ord ( "0" )
      p = p + 1

    if op == "+": 
      lv = lv + rv
    else:
      lv = lv * rv

  return ( lv )

e = input ( )
r = int ( input ( ) )
m = solvM ( e )
l = solvL ( e )

if ( m == r and l == r ):
  print ( "U" )
elif ( m == r ):
  print ( "M" )
elif ( l == r ):
  print ( "L" )
else:
  print ( "I" )

Submission status: Accepted

Solution code:
import re
class c(int):
    def __add__(self,n):
        return c(int(self)+int(n))
    def __mul__(self,n):
        return c(int(self)*int(n))

s=input()
d=int(input())
a=eval(re.sub(r'(\d+)',r'c(\1)',s))
b=int(s[0])
for i in range(1,len(s),2):
    if s[i]=='+':b+=int(s[i+1])
    else:b*=int(s[i+1])
if(a==b==d):e='U'
elif(a==d):e='M'
elif(b==d):e='L'
else:e='I'
print(e)

Submission status: Accepted

Solution code:
s,c=input(),int(input())
a=eval(s)
b=int(s[0])
for i in range(1,len(s),2):b=b+int(s[i+1]) if s[i]=='+' else b*int(s[i+1])
if(a==b==c):e='U'
elif(a==c):e='M'
elif(b==c):e='L'
else:e='I'
print(e)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
def parse1(s):
    cur = 0
    num = 0; res = 0; op = '+'
    while cur < len(s):
        if s[cur] in '+*':
            if op is '+':
                res += num
            else:
                res *= num
            num = 0; op = s[cur]
        else:
            num = 10 * num + int(s[cur])
        cur += 1
    if op is '+':
        res += num
    else:
        res *= num
    return res
def parse2(s):
    cur = 0
    def number():
        nonlocal cur
        v = int(s[cur]); cur += 1
        return v
    def term():
        nonlocal cur
        res = 1
        while 1:
            res *= number()
            if l <= cur or s[cur] != '*':
                break
            cur += 1
        return res
    def expr():
        nonlocal cur
        res = 0
        while 1:
            res += term()
            if l <= cur or s[cur] != '+':
                break
            cur += 1 # '+'
        return res
    return expr()
v = int(input())
r1 = parse1(s) == v
r2 = parse2(s) == v
print("ILMU"[r1+2*r2])

Submission status: Accepted

Solution code:
def left2right(formula):
    ans = int(formula[0])
    for i in range(1,len(formula),2):
        ans = eval(str(ans) + formula[i:i+2])
    return ans

formula = input()
val = int(input())
if left2right(formula) == val:
    print('U' if eval(formula) == val else 'L')
else:
    print('M' if eval(formula) == val else 'I')

Submission status: Accepted

Solution code:
s = '+'+input()
p = int(input())
n = 0
for a in [i+j for (i,j) in zip(s[::2], s[1::2])]:
    n = eval(str(n)+a)
f = 1 if n==p else 0
f += 2 if eval(s)==p else 0
print('ILMU'[f])

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        a = [c for c in S()]
        l = len(a)
        s = I()
        t = int(a[0])
        for i in range(len(a)//2):
            if a[i*2+1] == '+':
                t += int(a[i*2+2])
            else:
                t *= int(a[i*2+2])
        u = eval(''.join(a))
        r = 'I'
        if s == u:
            if s == t:
                r = 'U'
            else:
                r = 'M'
        elif s == t:
            r = 'L'

        rr.append(r)
        break


    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

S = input()
bob = int(input())

M = eval(S)

L = int(S[0])

for o, v in zip(S[1::2], S[2::2]):
    if o == "*":
        L *= int(v)
    else:
        L += int(v)

if M == L == bob:
    print("U")
elif M == bob:
    print("M")
elif L == bob:
    print("L")
else:
    print("I")

Submission status: Accepted

Solution code:
def f(s):
    return eval(s)
    
def g(s):
    ret = ord(s[0])-48
    i = 1
    while i < len(s):
        if s[i] == '+':
            ret += ord(s[i+1])-48
        else:
            ret *= ord(s[i+1])-48
        i += 2
    return ret

s = input()
n = int(input())
f1, f2 = (n == f(s)), (n == g(s))
if f1 and f2:
    print("U")
elif f1:
    print("M")
elif f2:
    print("L")
else:
    print("I")

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    m = II()
    ans = ["I", "L", "M", "U"]
    nu = 0
    stack = []
    bf = int(s[0])
    for num,si in enumerate(s):
        if si == "+":
            bf += int(s[num+1])
        elif si == "*":
            bf *= int(s[num + 1])
    if bf == m:
        nu += 1
    stack = []
    bf = 0
    for num, si in enumerate(s):
        if si == "*":
            s[num + 1] = int(s[num + 1]) * int(s[num - 1])
            s[num - 1] = 0
    for si in s:
        if si != "*" and si != "+":
            bf += int(si)
    if bf == m:
        nu += 2
    print(ans[nu])    

    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = input()
    c = I()
    a = eval(s)
    b = int(s[0])
    n = len(s)
    if n == 1:
        if int(s[0]) == c:
            print("U")
        else:
            print("I")
        quit()
    key = 0 if s[1] == "+" else 1
    for i in range(2,n):
        if not i%2:
            if key:
                b *= int(s[i])
            else:
                b += int(s[i])
        else:
            key = 0 if s[i] == "+" else 1
    if a == b:
        if a == c:
            print("U")
        else:
            print("I")
    elif a == c:
        print("M")
    elif b == c:
        print("L")
    else:
        print("I")
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Accepted

Solution code:
# coding: utf-8
import functools

def M(s):
    s=s.split('+')
    for i in range(len(s)):
        if '*' in s[i]:
            s[i]=functools.reduce(lambda x,y:str(int(x)*int(y)),s[i].split('*'))
    return int(functools.reduce(lambda x,y:str(int(x)+int(y)),s))

def L(s):
    ret=0
    i=0
    ope=1
    while i<len(s):
        if i%2==0:
            if ope==1:
                ret+=int(s[i])
            else:
                ret*=int(s[i])
        else:
            if s[i]=='+':
                ope=1
            else:
                ope=2
        i+=1
    return ret

original=input()
ans=int(input())
f=0
if ans==M(original):
    f+=1
if ans==L(original):
    f+=2

if f==0:
    print('I')
elif f==1:
    print('M')
elif f==2:
    print('L')
else:
    print('U')