_,a,b=`dd`.split f=->x,y{b[/.{#{N}}(?
#{x}\g
*#{y})/].size} p b[N=a.to_i-1])?f['\(','\)']:(b.reverse!;b.size-f['\)','\('])