#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int h, w, n;

bool solve(int y, int x, vector<vector<char>> &board) {
	vector<vector<char>> v = board;
	int x1 = x - 1, x2 = x;
	swap(v[y][x1], v[y][x2]);
	while(true) {
		for(int j = 0; j < w; ++j) {
			int cnt = h - 1;
			for(int i = h - 1; i >= 0; --i) {
				if(v[i][j] != '.') {
					swap(v[i][j], v[cnt][j]);
					--cnt;
				}
			}
		}
		vector<vector<char>> ans = v;
		bool flg = false;
		for(int i = 0; i < h; ++i) {
			char pre = '!';
			int cnt = 0;
			for(int j = 0; j < w; ++j) {
				if(pre != v[i][j]) {
					if(cnt >= n and pre != '.') {
						for(int k = 1; k <= cnt; ++k) {
							ans[i][j - k] = '.';
						}
						flg = true;
					}
					cnt = 1;
					pre = v[i][j];
				} else {
					cnt++;
				}
			}
			if(cnt >= n and pre != '.') {
				for(int k = 1; k <= cnt; ++k) {
					ans[i][w - k] = '.';
				}
				flg = true;
			}
		}
		for(int j = 0; j < w; ++j) {
			char pre = '!';
			int cnt = 0;
			for(int i = 0; i < h; ++i) {
				if(pre != v[i][j]) {
					if(cnt >= n and pre != '.') {
						for(int k = 1; k <= cnt; ++k) {
							ans[i - k][j] = '.';
						}
						flg = true;
					}
					cnt = 1;
					pre = v[i][j];
				} else {
					cnt++;
				}
			}
			if(cnt >= n and pre != '.') {
				for(int k = 1; k <= cnt; ++k) {
					ans[h - k][j] = '.';
				}
				flg = true;
			}
		}
		if(not flg) {
			bool ret = true;
			for(int i = 0; i < h; ++i) {
				for(int j = 0; j < w; ++j) {
					// cerr << ans[i][j];
					if(ans[i][j] != '.') ret = false;
				}
				// cerr << endl;
			}
			return ret;
		}
		v = ans;
	}
}

int main() {
	cin >> h >> w >> n;
	vector<vector<char>> board(h, vector<char>(w));
	rep(i,h)rep(j,w) cin >> board[i][j];
	for(int i = 0; i < h; ++i) {
		for(int j = 1; j < w; ++j) {
			if(solve(i, j, board)) {
				cout << "YES" << '\n';
				return 0;
			}
		}
	}
	cout << "NO" << '\n';
	return 0;
}
