#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
#include<unordered_set>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

bool lis[40][40];
string s[40], t[40];
signed main(void)
{
	int h, w, n;
	cin >> h >> w >> n;
	REP(i, h) cin >> s[i];

	//(i, j)??¨(i, j+1)?????\?????????
	REP(i, h) REP(j, w-1) {
		if(s[i][j] == '.' && s[i][j+1] == '.') continue;
		//cout << i << " " << j << endl;
		REP(k, h) t[k] = s[k];
		//cout << i << " " << j << endl;
		//REP(k, h) cout << t[k] << endl;
		swap(t[i][j], t[i][j+1]);
		//????????????
		REP(k, w) REP(l, h)	{
			bool ra = false;
			for(int l2=h-1; l2>=1; --l2) {
				//cout << k << " " << l2 << endl;
				if(t[l2][k] == '.') ra = true;
				if(ra) {t[l2][k] = t[l2-1][k]; t[l2-1][k] = '.';}
			}
		}
		while(true) {
			//?¨?????????§n??\???????????§?????¨??????????¶????
			REP(k, h) REP(l, w) lis[k][l] = false;
			REP(k, h) {
				int c = 1;
				FOR(l, 1, w) {
					if(t[k][l] == t[k][l-1] && t[k][l] != '.') c++;
					else {
						if(c >= n) REP(l2, c) lis[k][l-l2-1] = true;
						c = 1;
					}
				}
				if(c >= n) REP(l2, c) lis[k][w-l2-1] = true;
			}
			//???????????§n??\???????????§?????¨??????????¶????
			REP(l, w) {
				int c = 1;
				FOR(k, 1, h) {
					if(t[k][l] == t[k-1][l] && t[k][l] != '.') c++;
					else {
						if(c >= n) REP(l2, c) lis[k-l2-1][l] = true;
						c = 1;
					}
				}
				if(c >= n) REP(l2, c) lis[h-l2-1][l] = true;
			}
			//cout << "y:" << i << " x:" << j << endl;
			//lis???true?????¨??????????¶???? ???????????°break
			bool flag = false;
			REP(k, h) {
				REP(l, w) {
					//cout << (lis[k][l]?"o ":"x ");
					if(lis[k][l]) {
						flag = true;
						t[k][l] = '.';
					}
				}
				//cout << endl;
			}
			//cout << "b" << endl;
			/*REP(k, h) {
				REP(l, w) {
					cout << t[k][l] << " ";
				}
				cout << endl;
			}*/
			if(!flag) {
				//??¨??¨'.'????¢??????????????????????Yes?????? return 0;
				bool f2 = true;
				REP(k, h) REP(l, w) {
					if(t[k][l] != '.') f2 = false;
				}
				//cout << "a" << endl;
				if(f2) {cout << "YES" << endl; return 0;}
				break;
			}
			//????????????
			REP(k, w) REP(l, h)	{
				bool ra = false;
				for(int l2=h-1; l2>=1; --l2) {
					//cout << k << " " << l2 << endl;
					if(t[l2][k] == '.') ra = true;
					if(ra) {t[l2][k] = t[l2-1][k]; t[l2-1][k] = '.';}
				}
			}
			//cout << endl;
			//if(i == 2 && j == 2) REP(k, h) cout << t[k] << endl;
		}
	}
	cout << "NO" << endl;
	return 0;
}