class Calc0049 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @s = args.shift.first end def run stack = [] @s.scan(/\d+|[+*]/).each do |t| case t when /\d+/ t = t.to_i if stack.empty? stack.push(t) else op = stack.pop target = stack.pop case op when '+' stack.push(target * t) when '*' stack.push(target + t) end end when '+', '*' stack.push(t) end end stack.pop end end puts Calc0049.new(STDIN.readlines).run if __FILE__ == $0