package main import "fmt" func main () { // 入力 var len, cursor int var brackets string fmt.Scan(&len, &cursor) fmt.Scan(&brackets) targetChar := brackets[cursor - 1:cursor] ans := cursor cnt := 0 if targetChar == "(" { for ; ; ans++ { if brackets[ans - 1: ans] == "(" { cnt++ } else { cnt-- } if cnt <= 0 { break } } } else { for ; ; ans-- { if brackets[ans - 1: ans] == ")" { cnt++ } else { cnt-- } if cnt <= 0 { break } } } fmt.Println(ans) }