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