require 'set'
h, w, N = gets.split.map(&:to_i)

cols = (1..h).map { gets.chomp.split("") }.transpose.map(&:reverse)
GOAL = [ [?.] * h ] * w

def check_swap(cols, c1, r1, c2, r2)
    return nil if cols[c1][r1] == cols[c2][r2]

    copy = cols.map(&:dup)
    copy[c1][r1], copy[c2][r2] = copy[c2][r2], copy[c1][r1]

    drop(copy)
    drop(copy) while changed = erase(copy) 

    return copy == GOAL
end

def erase(cols)
    to_be_erased = Set.new
    (0..cols.size-1).each do |i|
        x = nil
        n = 0
        cols[i].each.with_index do |y, j|
            if y == ?.
                n = 0
            elsif y == x
                n += 1
            else
                x = y
                n = 1
            end
            if n == N
                (0..n-1).each do |k|
                    to_be_erased << [i, j-k]
                end
            elsif n > N
                to_be_erased << [i, j]
            end
            x = y
        end
    end

    (0..cols[0].size-1).each do |j|
        x = nil
        n = 0
        (0..cols.size-1).each do |i|
            y = cols[i][j]
            if y == ?.
                n = 0
            elsif y == x
                n += 1
            else
                x = y
                n = 1
            end
            if n == N
                (0..n-1).each do |k|
                    to_be_erased << [i-k, j]
                end
            elsif n > N
                to_be_erased << [i, j]
            end
            x = y
        end
    end

    to_be_erased.each do |i, j|
        cols[i][j] = ?.
    end

    return ! to_be_erased.empty?
end

def drop(cols)
    cols.map! do |col|
        n = col.size
        col.delete(?.)
        col += [?.] * (n - col.size)
    end
end

(0..w-2).each do |c|
    (0..h-1).each do |r|
        if check_swap(cols, c, r, c+1, r)
            puts 'YES'
            exit
        end
    end
end

puts 'NO'