function checkFn() {
   while (true) {
      for (var x = 0; x < w ; x++) {
         var yy=[];
         for (var y = h-1; y >=0 ; y--) {
               if(yx[y][x]!=".")yy.push(yx[y][x]);
               yx[y][x]=".";
         }
         for (var y = h-1; y >=0 ; y--) {
            if(yy.length!=0)yx[y][x]=yy.shift();
            else yx[y][x]=".";
         }
      }
      var memo = [];
      for (var y = 0; y < h; y++)
         for (var x = 0; x <= w - n; x++) {
            var color = yx[y][x];
            if (color == ".") continue;
            var flag = true;
            for (var i = 1; i < n; i++) {
               if (yx[y][x + i] != color) flag = false;
            }
            if (flag) {
               for (var i = 0; i < n; i++) memo.push([y, x + i]);
            }
         }
      for (var y = 0; y <= h - n; y++)
         for (var x = 0; x < w; x++) {
            var color = yx[y][x];
            if (color == ".") continue;
            var flag = true;
            for (var i = 1; i < n; i++) {
               if (yx[y + i][x] != color) flag = false;
            }
            if (flag) {
               for (var i = 0; i < n; i++) memo.push([y + i, x]);
            }
         }
      memo.forEach(v => {
         yx[v[0]][v[1]] = ".";
      });
      if (memo.length == 0) break;
   }
   var str = yx.join("");
   return !(/[A-Z]/.test(str));
};

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
var [h, w, n] = arr.shift().split(" ").map(Number);
var YX = [];
for (var i = 0; i < h; i++) YX.push(arr.shift().split(""));

var flag = false;
for (var y = 0; y < h; y++) {
   for (var x = 0; x < w - 1; x++) {
      var yx = YX.map(v => v.slice());
      [yx[y][x], yx[y][x + 1]] = [yx[y][x + 1], yx[y][x]];
      if (checkFn()) flag = true;
   }
}

console.log(flag ? "YES" : "NO");
