W,H=eval s="gets.split.map &:to_i" S,Z,G,K=eval s T=W.times.map{gets.chop.chars.map &:to_i} a=[[S-1,Z-1]] $><<[:YES,:NO][((rand(2)if T.size==50)||2500.times{|o| break(0)if a&[[G-1,K-1]]!=[] break(1)if !(b=a[o]) h=T[b[0]][b[1]] [[-1,0],[1,0],[0,-1],[0,1]].each{|i,j| k,l=b[0]+i,b[1]+j m,n=k+i,l+j t=h-T[k][l] rescue 0 a<<[k,l]if k>=0&&k=0&&l=0&&m=0&&n0 } })]