#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<char, bool>P;

string s[30];
P t[30][30];
int main() {
	int h, w, n; scanf("%d%d%d", &h, &w, &n);
	rep(i, h)cin >> s[i];
	rep(i, h)rep(j, w - 1) {
		rep(i, h)rep(j, w)t[i][j].first = s[i][j];
		swap(t[i][j].first, t[i][j + 1].first);
		bool update = true;
		while (update) {
			rep(k, h + 1) {
				rep(i, h - 1)rep(j, w) {
					if (t[i][j].first != '.'&&t[i + 1][j].first == '.')
						swap(t[i][j].first, t[i + 1][j].first);
				}
			}
			rep(i, h)rep(j, w)t[i][j].second = false;
			update = false;
			rep(i, h) {
				int cnt = 0; char c = t[i][0].first;
				rep(j, w) {
					if (t[i][j].first == '.' || t[i][j].first != c) {
						if (cnt >= n) {
							rep(k, cnt)t[i][j - k - 1].second = true;
						}
						c = t[i][j].first;
						if (t[i][j].first == '.')cnt = 0;
						else cnt = 1;
					}
					else cnt++;
				}
				if (cnt >= n) {
					rep(k, cnt)t[i][w - k - 1].second = true;
				}
			}
			rep(i, w) {
				int cnt = 0; char c = t[0][i].first;
				rep(j, h) {
					if (t[j][i].first == '.' || t[j][i].first != c) {
						if (cnt >= n) {
							rep(k, cnt)t[j - k - 1][i].second = true;
						}
						c = t[j][i].first;
						if (t[j][i].first == '.')cnt = 0;
						else cnt = 1;
					}
					else cnt++;
				}
				if (cnt >= n) {
					rep(k, cnt)t[h - k - 1][i].second = true;
				}
			}
			rep(i, h)rep(j, w) {
				if (t[i][j].second) {
					t[i][j].first = '.';
					update = true;
				}
			}
		}
		bool ok = true;
		rep(i, h)rep(j, w) {
			if (t[i][j].first != '.')ok = false;
		}
		if (ok) {
			puts("YES"); return 0;
		}
	}
	puts("NO");
}