def f(x,a="") return[a]if""==x h=x[0,1] t=x[1..-1] case h when'f' f t,h when'(' b,u=f t f u,"(#{a} #{b})" else [a,t] end end loop{puts f(gets)[0]}