class Yukidama attr_accessor :range attr_reader :yuki def initialize(range, yuki) @range = range @yuki = yuki end def merge!(other) original_range = @range if @range.nil? new_first = other.range.first + @yuki new_last = other.range.last + @yuki if new_last < 1 new_first = new_last = 0 elsif new_first < 1 new_first = other.range.first.even? ? 1 : 2 end @range = new_first..new_last else new_first = [@range.first, other.range.first + @yuki].min new_last = [@range.last, other.range.last + @yuki].max if new_last < 1 new_first = new_last = 0 elsif new_first < 1 new_first = other.range.first.even? ? 1 : 2 end new_last = Float::INFINITY if @range.last < new_last @range = new_first..new_last end return (original_range && original_range != @range) || (original_range.nil? && @range != (0..0)) end def to_s @range.nil? ? "___" : "#{@range.first}-#{@range.last==Float::INFINITY ? ?X : @range.last}" end end h, w = gets.split.map(&:to_i) a, si, sj = gets.split.map(&:to_i) b, gi, gj = gets.split.map(&:to_i) if (a+si+sj+b+gi+gj).odd? puts 'No' exit end yuki = h.times.map{ gets.chars.map{|c| c==?*?1:-1 } } map = Array.new(h){|i| Array.new(w){|j| Yukidama.new(nil, yuki[i][j]) } } map[si][sj].range = a..a stack = [[si, sj]] while stack.size > 0 i, j = stack.shift d = map[i][j] [[i-1,j],[i+1,j],[i,j-1],[i,j+1]].each{|i,j| next unless 0 <= i && i < h && 0 <= j && j < w if map[i][j].merge!(d) stack.push [i,j] end } if map[gi][gj].range && map[gi][gj].range.include?(b) puts 'Yes' exit end end puts 'No'