program main implicit none integer::N,K,i,depth=0,res integer,parameter::maxlength=10000 character(len=maxlength)::S character,parameter::l='(',r=')' read *, N, K, S if (S(K:K).eq.l) then do i=K, LEN_TRIM(S), 1 if(S(i:i).eq.l) then depth = depth + 1 else depth = depth - 1 end if if (depth.eq.0) then res = i exit end if end do else do i=K, 1, -1 if(S(i:i).eq.l) then depth = depth + 1 else depth = depth - 1 end if if (depth.eq.0) then res = i exit end if end do end if print '(i0)', res end program main