#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Block {
public:
	char c;
	bool flag;
};

int dx[] = { 1,-1 };
int dy[] = { 0,0 };
int h, w, n;

void fall(vector<vector<Block>>& grid)
{
	for (int x = 0; x < w; x++) {
		for (int y = 0; y < h - 1; y++) {
			for (int k = h - 1; k > y; k--) {
				if (grid[k][x].c == '.'&&grid[k - 1][x].c != '.') {
					swap(grid[k][x], grid[k - 1][x]);
				}
			}
		}
	}
}

bool check(vector<vector<Block>>& grid)
{
	bool flag = true;

	while (true) {
		bool deleteflag = false;

		fall(grid);//??????

		//?¨???????????¶????(????????°???????????????)
		for (int y = 0; y < h; y++) {
			int count = 1;
			int startx = 0;
			char now = grid[y][0].c;

			for (int x = 1; x < w; x++) {
				if (grid[y][x].c == '.') {
					if (count >= n) {
						for (int xx = 0; xx < count; xx++) {
							grid[y][startx + xx].flag = false;
							deleteflag = true;
						}
					}

					count = 1;
					now = '.';
					continue;
				}

				if (grid[y][x].c == now) {
					count++;
				}
				else {
					if (count >= n) {
						for (int xx = 0; xx < count; xx++) {
							grid[y][startx + xx].flag = false;
							deleteflag = true;
						}
					}

					count = 1;
					startx = x;
					now = grid[y][x].c;
				}
			}

			if (count >= n) {
				for (int xx = 0; xx < count; xx++) {
					grid[y][startx + xx].flag = false;
					deleteflag = true;
				}
			}
		}

		//?????????????¶????(????????°???????????????)
		for (int x = 0; x < w; x++) {
			int count = 1;
			int starty = 0;
			char now = grid[0][x].c;

			for (int y = 1; y < h; y++) {
				if (grid[y][x].c == '.') {
					if (count >= n) {
						for (int yy = 0; yy < count; yy++) {
							grid[starty + yy][x].flag = false;
							deleteflag = true;
						}
					}

					count = 1;
					now = '.';
					continue;
				}

				if (grid[y][x].c == now) {
					count++;
				}
				else {
					if (count >= n) {
						for (int yy = 0; yy < count; yy++) {
							grid[starty + yy][x].flag = false;
							deleteflag = true;
						}
					}

					count = 1;
					starty = y;
					now = grid[y][x].c;
				}
			}

			if (count >= n) {
				for (int yy = 0; yy < count; yy++) {
					grid[starty + yy][x].flag = false;
					deleteflag = true;
				}
			}
		}

		//??????????¶??????????
		if (deleteflag == true) {
			for (int y = 0; y < h; y++) {
				for (int x = 0; x < w; x++) {
					if (grid[y][x].flag == false) {
						grid[y][x].c = '.';
					}
				}
			}
		}
		else {
			break;
		}
	}

	for (int y = 0; y < h; y++) {
		for (int x = 0; x < w; x++) {
			if (grid[y][x].c != '.') {
				flag = false;
			}
		}
	}

	return flag;
}

int main() {
	cin >> h >> w >> n;

	vector<vector<Block>> grid(h, vector<Block>(w));

	for (int y = 0; y < h; y++) {
		for (int x = 0; x < w; x++) {
			cin >> grid[y][x].c;

			if (grid[y][x].c == '.') {
				grid[y][x].flag = false;
			}
			else {
				grid[y][x].flag = true;
			}
		}
	}

	for (int y = 0; y < h; y++) {
		for (int x = 0; x < w; x++) {
			for (int k = 0; k < 2; k++) {
				int ny = y + dy[k];
				int nx = x + dx[k];

				if (ny < 0 || ny >= h || nx < 0 || nx >= w) {
					continue;
				}

				vector<vector<Block>> temp = grid;
				swap(temp[y][x], temp[ny][nx]);

				if (check(temp) == true) {
					cout << "YES" << endl;
					return 0;
				}
			}
		}
	}

	cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 3168