n = read_line.to_i a = read_line.split stack = Deque(Int32).new a.each do |i| if i == "+" b, a = stack.pop, stack.pop stack.push(a + b) elsif i == "-" b, a = stack.pop, stack.pop stack.push(a - b) else stack.push(i.to_i) end end puts stack.last