integer n, lowest, now
character(100):: s, top,tail
read*,n
read*,s
s = trim(s)
lowest=0; now=0
do i = 1,n
  if(s(i:i) == "(")then
    now = now + 1
  else
    now = now - 1
  end if
  lowest = min(lowest,now)
end do
top = ''
tail= ''
if(lowest<0)top =repeat("(",-lowest)
if(now>lowest)tail=repeat(")",now-lowest)

print'(a)', trim(top) // trim(s) // trim(tail) 

end