program abc064_d
    use,intrinsic :: iso_fortran_env
    implicit none
    character(:), allocatable:: s
    character(200), allocatable:: ans
    integer(int32):: n,i
    integer(int32), allocatable:: cnt(:)

    read*, n
    allocate(character(n):: s)
    allocate(cnt(0:n))
    read*, s

    cnt(:) = 0
    do i=1,n
        if (s(i:i) == '(' ) then
            cnt(i)=cnt(i-1)+1
        else
            cnt(i)=cnt(i-1)-1
        end if
    end do

    ans = ''

    do i=1,abs(min(0,minval(cnt)))
        ans = '(' // trim(ans)
    end do

    ans = trim(ans) // s

    do i=1,cnt(n)-minval(cnt)
        ans = trim(ans) // ')'
    end do

    print'(a)', ans
end program abc064_d