h, w = gets.split.map(&:to_i) s = h.times.map{ gets.chomp!.split(//).map{|c| '#' == c } } class Image def initialize(a) @a = a.map{|row| row.clone } @row_size = @a.length @column_size = @a[0].length end attr_reader :row_size, :column_size def [](x, y) @a[x][y] end def []=(x, y, val) @a[x][y] = val end def clone self.class.new(@a.map{|row| row.clone }) end def shift(dx, dy) row_ids = (0...row_size).to_a row_ids.reverse! if 0 <= dx col_ids = (0...column_size).to_a col_ids.reverse! if 0 <= dy row_ids.each do |i| col_ids.each do |j| self[i, j] = include_index?(i-dx, j-dy) ? self[i-dx, j-dy] : false end end self end def include_index?(i, j) 0 <= i && i < row_size && 0 <= j && j < column_size end def &(other) result = self.clone each_index do |i, j| result[i, j] &= other[i, j] end result end def ^(other) result = self.clone each_index do |i, j| result[i, j] ^= other[i, j] end result end def ==(other) each_index do |i, j| return false if self[i, j] != other[i, j] end true end def each_index row_size.times do |i| column_size.times do |j| yield(i, j) end end end end image = Image.new(s) ok = false h.times do |dx| break if ok ((1-w)...w).each do |dy| break if ok next if 0 == dx && 0 == dy mask = image.clone.shift(dx, dy) half_image = (image & mask).shift(-dx, -dy) ok |= image == (half_image ^ half_image.clone.shift(dx, dy)) end end puts ok ? 'YES' : 'NO'