main=interact$concat.reverse.foldl(#)[] x#'('=x (a:f:x)#')'=('(':f++' ':a++")"):x x#a=[a]:x