@x=[] a=[] @t=[] n,k = gets.chomp.split(" ").map(&:to_i) @x+=gets.chomp.split(" ").map(&:to_i) a+=gets.chomp.split(" ").map(&:to_i) @hash = Hash[*([@x,a].transpose.flatten)] @c=0 p=@x[k-1] b=a[k-1] def f(p,w) b = @hash[p] zzz = p+w*b zzz1 = p+(-1*w*b) @x.each do |elm| if zzz1 > zzz if elm >=zzz and zzz1 >= elm if @t.any? {|w| w == elm } next else @t.push(elm) end f(elm,1) f(elm,-1) end else if zzz >= elm and elm >= zzz1 if @t.any? {|w| w == elm } next else @t.push(elm) end f(elm,1) f(elm,-1) end end end @c+=1 end f(p,1) f(p,-1) @t=[0] if @t==nil p @t.length