m@main=getLine>>=putStrLn.head.foldl(#)["",""]>>m u@(v:w:x)#y|y:v==")"=(w++[y]):x|v==""=[y]:w:x|y<')'="":u|0<1=('(':w++' ':v++[y]):x