read n k read s ${s//(/q[d++]=++i,} echo $[${_//)/p[p[i]=j=q[--d]]=++i,}p[k]]