#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAXH 32
#define MAXW 32

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

char field[MAXH][MAXW];

int main(void) {
    int h, w, n;
    cin >> h >> w >> n;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> field[i][j];
        }
    }
    // 全ての交換について全探索
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w-1; j++) {
            // 交換(bufは作業用)
            char buf[MAXH][MAXW];
            for (int y = 0; y < h; y++) {
                for (int x = 0; x < w; x++) {
                    buf[y][x] = field[y][x];
                }
            }
            char tmp = buf[i][j];
            buf[i][j] = buf[i][j+1];
            buf[i][j+1] = tmp;
            while (1) {
                // 落とす
                for (int y = h-2; y >= 0; y--) {
                    for (int x = 0; x < w; x++) {
                        if (buf[y][x] != '.') {
                            int ny = y+1;
                            if (buf[ny][x] != '.') continue;
                            while (ny < h && buf[ny][x] == '.') ny++;
                            buf[ny-1][x] = buf[y][x];
                            buf[y][x] = '.';
                        }
                    }
                }
                // 消せるところを探せ
                bool delete_flag = false;
                bool can_delete[MAXH][MAXW];
                for (int y = 0; y < h; y++) {
                    for (int x = 0; x < w; x++) {
                        can_delete[y][x] = false;
                    }
                }
                // 横で消せるやつ
                for (int y = 0; y < h; y++) {
                    for (int x = 0; x < w-n+1; x++) {
                        if (buf[y][x] == '.' /*|| can_delete[y][x] == true*/) continue;
                        int cnt = 1;
                        char c = buf[y][x];
                        int nx = x + 1;
                        while (nx < w && buf[y][nx] == c) {
                            nx++;
                            cnt++;
                        }
                        if (cnt >= n) {
                            delete_flag = true;
                            for (int k = x; k < nx; k++) can_delete[y][k] = true;
                        }
                    }
                }
                // 縦で消せるやつ
                for (int y = 0; y < h-n+1; y++) {
                    for (int x = 0; x < w; x++) {
                        if (buf[y][x] == '.') continue;
                        int cnt = 1;
                        char c = buf[y][x];
                        int ny = y + 1;
                        while (ny < h && buf[ny][x] == c) {
                            ny++;
                            cnt++;
                        }
                        if (cnt >= n) {
                            delete_flag = true;
                            for (int k = y; k < ny; k++) can_delete[k][x] = true;
                        }
                    }
                }
                if (!delete_flag) break;
                // 消す
                for (int y = 0; y < h; y++) {
                    for (int x = 0; x < w; x++) {
                        if (can_delete[y][x]) buf[y][x] = '.';
                    }
                }
            }
            bool ok = true;
            for (int y = 0; y < h; y++) {
                for (int x = 0;  x < w; x++) {
                    if (buf[y][x] != '.') {
                        ok = false;
                        break;
                    }
                }
                if (!ok) break;
            }
            if (ok) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 1160