@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] def aaa(elm) if @t.any? {|w| w == elm } return true else @t.push(elm) end end update = true while(update) b = @hash[p] zzz = p+b zzz1 = p+(-1*b) @x.each do |elm| if zzz1 > zzz if elm >=zzz and zzz1 >= elm next if aaa(elm)== true p = elm break elsif @x.last == elm update = false end else if zzz >= elm and elm >= zzz1 next if aaa(elm)== true p = elm break elsif @x.last == elm update = false end end end end if @t==nil p "1" else p @t.length end