#! ruby # yukicoder My Practice # author: Leonardone @ NEETSDKASU def gs() gets.chomp end def gi() gets.to_i end def gss() gets.chomp.split end def gis() gss.map(&:to_i) end def nmapf(n,f) n.times.map{ __send__ f } end def arr2d(h,w,v=0) h.times.map{[v] * w} end def ngs(n) nmapf n,:gs end def ngi(n) nmapf n,:gi end def ngss(n) nmapf n,:gss end def ngis(n) nmapf n,:gis end require 'set' H, W = gis A, Si, Sj = Start = gis B, Gi, Gj = Goal = gis $M = ngs H AnsYes = 'Yes' AnsNo = 'No' l = (Si - Gi).abs + (Sj - Gj).abs if l.even? && (A.even? == B.even?) puts AnsNo exit end if l.odd? && (A.even? != B.even?) puts AnsNo exit end $minus = arr2d H,W $plus = arr2d H,W $minus[Si][Sj] = A def chk(rch2, c, y2, x2) if $M[y2][x2] == '*' if $plus[y2][x2] == 0 rch2 << [c + 1, y2, x2] $plus[y2][x2] = 1 end elsif c > 1 && $minus[y2][x2] < c - 1 rch2 << [c - 1, y2, x2] $minus[y2][x2] = c - 1 end end rch1 = [Start] while !rch1.empty? rch2 = [] rch1.each do |c,y,x| chk rch2, c, y, x - 1 if x > 0 chk rch2, c, y - 1, x if y > 0 chk rch2, c, y, x + 1 if x + 1 < W chk rch2, c, y + 1, x if y + 1 < H end rch1 = rch2 end H.times do |i| (1...W).each do |j| if $plus[i][j] > 0 && $plus[i][j - 1] > 0 puts AnsYes exit end end end W.times do |j| (1...H).each do |i| if $plus[i][j] > 0 && $plus[i - 1][j] > 0 puts AnsYes exit end end end puts AnsNo