class Main def start a = wash(input.split("")).reverse v = 1 s = "*" while true x, flg = get_next_value a v = calc(v, x, s) break if not flg a, s = get_next_symbol a end echo ans = v return nil end private def calc(v, x, s) case s when "*" v * x when "+" v + x end end def get_next_symbol(a) s = a.pop return a, s end def get_next_value(a) s = "" while a.size > 0 && (0..9).map(&:to_s).include?(a.last) s += a.pop end flg = a.size > 0 ? true : false return s.to_i, flg end def wash(a) b = [] for ai in a case ai when "*" b += ["+"] when "+" b += ["*"] else b += [ai] end end return b end def echo(*x) print(*x) puts end def input = gets.chomp end Main.new.start