program prob5
    implicit none
    integer::i, j, l, r, n, cnt
    character(len=100)::S
    character(len=300)::ans
    read(*,*) n
    read(*,*) S
    ans = ""
    l = 0
    r = 0
    cnt = 0
    do i = 1, n
        if(S(i:i) .eq. "(") then
            ans = trim(ans) // "("
            cnt = cnt + 1
        else
            ans = trim(ans) // ")"
            cnt = cnt - 1
            if(cnt < 0) then
                ans = "(" // trim(ans)
                cnt = 0
            end if
        end if
    end do
    if(cnt > 0) then
        do i = 1, cnt
            ans = trim(ans) // ")"
        end do
    end if
    write(*,'(a)') trim(ans)
    stop
end program