def solve(fld)
  $h.times do |y|
    fld[y].each_cons(2).with_index do |(a, b), x|
      if a != b  && a != '.' && b != '.'
        fld[y][x], fld[y][x+1] = fld[y][x+1], fld[y][x]
        return true if search(fld)
        fld[y][x], fld[y][x+1] = fld[y][x+1], fld[y][x]
      end
    end
  end
  false
end

def search(fld)
  return true if fld.flatten.all?{ |v| v == '.' }
  res = []
  $h.times do |y|
    fld[y].each_cons($n).with_index do |ar, x|
      next if ar[0] == '.'
      res << [y, x, 0] if ar.all?{|v| v == fld[y][x] }
    end
  end
  fld = fld.transpose
  $w.times do |x|
    fld[x].each_cons($n).with_index do |ar, y|
      next if ar[0] == '.'
      res << [y, x, 1] if ar.all?{|v| v == fld[x][y] }
    end
  end
  return false if res.size == 0
  res.each do |y, x, d|
    $n.times{ |i| fld[x][y + i] = nil } if d == 1
    $n.times{ |i| fld[x + i][y] = nil } if d == 0
  end
  search(erase(fld))
end

def erase(fld)
  $w.times do |x|
    fld[x].compact!
    ($h - fld[x].size).times{ fld[x].unshift('.') }
  end
  fld.transpose
end
$h, $w, $n = gets.split.map(&:to_i)
fld = $h.times.map{ gets.chomp.split('') }
puts solve(fld) ? 'YES' : 'NO'