def solve(fld)
  $h.times do |y|
    fld[y].each_cons(2).with_index do |(a, b), x|
      if a != b
        fld[y][x], fld[y][x+1] = fld[y][x+1], fld[y][x]
        return true if chain(fld.transpose.map{ |ar| ar.reverse })
        fld[y][x], fld[y][x+1] = fld[y][x+1], fld[y][x]
      end
    end
  end
  false
end
  
def chain(fld)
  loop do
    $t = false
    adjust(fld)
    return true if $t
    $f = false
    fld = erase(fld, $w, $h, erase(fld.transpose, $h, $w).transpose)
    return false unless $f
  end
end
  
def erase(fld, r, c, nfld = fld)
  r.times do |y|
    fld[y].each_cons($n).with_index do |ar, x|
      next if ar.any?{ |v| !v }
      if ar.all?{ |v| v == ar[0] }
        $f = true
        while x < c && ar[0] == fld[y][x]
          nfld[y][x] = nil
          x += 1
        end
      end
    end
  end
  nfld
end
  
def adjust(fld)
  $w.times do |x|
    fld[x].map! { |v| v if /[A-Z]/ =~ v }.compact!
  end
  $t = true if fld.flatten.all?{|v| v.nil? }
  fld.map!{|ar| ar.fill(nil, ar.size...$h) }
end
  
$h, $w, $n = gets.split.map(&:to_i)
fld = $h.times.map{ gets.chomp.split('').map{ |v| v if /[A-Z]/ =~ v } }
puts solve(fld) ? 'YES' : 'NO'