@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)] p=@x[k-1] update = true @t=[nil] xxx = @x.length def aaa(elm) if @t.any? {|w| w == elm } return true else @t.compact! @t< zzz if @x[i] >=zzz and zzz1 >= @x[i] aaa(@x[i]) end else if zzz >= @x[i] and @x[i] >= zzz1 aaa(@x[i]) end end break if i == xxx-1 end else @t.each do |elm| b = @hash[elm] zzz = elm+b zzz1 = elm+(-1*b) for i in 0...xxx do update = false if i == xxx-1 if zzz1 > zzz if @x[i] >=zzz and zzz1 >= @x[i] aaa(@x[i]) end else if zzz >= @x[i] and @x[i] >= zzz1 aaa(@x[i]) end end end end end end if @t==nil p "1" else p @t.length end