s = gets.chomp.gsub(/(\d*)([*+])(\d+)/){$2=='*'?"#$1+#$3)":"#$1*#$3)"} s = '('*s.count(')') + s p eval s