def solve stack = [] A.each do |a| case a when /\d+/ stack << a.to_i when '+' a = stack.pop b = stack.pop stack << b + a when '-' a = stack.pop b = stack.pop stack << b - a end end stack.pop end N = gets.to_i A = gets.chomp.split puts solve