def solve(n, block)
  fall!(block)
  while delete!(n, block) != 0 do
    fall!(block)
  end
  clear(block)
end

def delete!(n, block)
  h = block.size
  w = block.first.size
  delete = Array.new(h) {Array.new(w)}
  for i in 0...h do
    for j in n-1...w do
      next if block[i][j] == "."
      ok = true
      for k in 1...n do
        ok = false if(block[i][j] != block[i][j-k])
      end
      next if !ok
      for k in 0...n do
        delete[i][j-k] = true
      end
    end
  end
  for j in 0...w do
    for i in n-1...h do
      next if block[i][j] == "."
      ok = true
      for k in 1...n do
        ok = false if(block[i][j] != block[i-k][j])
      end
      next if !ok
      for k in 0...n do
        delete[i-k][j] = true
      end
    end
  end
  count = 0
  for i in 0...h do
    for j in 0...w do
      next if !delete[i][j]
      block[i][j] = "."
      count += 1
    end
  end
  count
end

def fall!(block)
  h = block.size
  w = block.first.size
  for j in 0...w do
    for i in 0...h do
      next if block[h-i-1][j] != "."
      for k in i+1...h do
        next if block[h-k-1][j] == "."
        block[h-i-1][j], block[h-k-1][j] = block[h-k-1][j], block[h-i-1][j]
        break
      end
    end
  end
end

def clear(block)
  h = block.size
  w = block.first.size
  ok = true
  for i in 0...h do
    for j in 0...w do
      ok = false if block[i][j] != "."
    end
  end
  ok
end

h, w, n = gets.split.map(&:to_i)
block = []
h.times do
  block.push(gets.chomp)
end
ok = false
for i in 0...h do
  for j in 1...w do
    next if block[i][j-1] == block[i][j]
    block[i][j-1], block[i][j] = block[i][j], block[i][j-1]
    ok = true if solve(n, Marshal.load(Marshal.dump(block)))
    block[i][j-1], block[i][j] = block[i][j], block[i][j-1]
  end
end
puts ok ? "YES" : "NO"