#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

char cell[30][30];
char tmp[30][30];
bool exist[30][30];
bool txist[30][30];
int dh[2] = {1,0}, dw[2] = {0,1};

int main(){
	int h, w, n;
	cin >> h >> w >> n;
	rep(i,h) rep(j,w){
		cin >> cell[i][j];
		if(cell[i][j] == '.') exist[i][j] = false;
		else exist[i][j] = true;
	}
	rep(i,h){
		rep(j,w){
			rep(k,2){
				if(k == 0) continue;
				rep(u,h) rep(v,w){
					tmp[u][v] = cell[u][v];
					txist[u][v] = exist[u][v];
				}
				int th = i+dh[k];
				int tw = j+dw[k];
				if(th >= h || tw >= w || tmp[i][j] == tmp[th][tw]) continue;
				swap(tmp[i][j],tmp[th][tw]);
				swap(txist[i][j],txist[th][tw]);
				for(int f = h-1; f >= 0; f--){
					if(txist[f][j]) continue;
					for(int l = f-1; l >= 0; l--){
						if(txist[l][j]){
							swap(txist[l][j],txist[f][j]);
							swap(tmp[l][j],tmp[f][j]);
							break;
						}
					}
				}
				for(int f = h-1; f >= 0; f--){
					if(txist[f][tw]) continue;
					for(int l = f-1; l >= 0; l--){
						if(txist[l][tw]){
							swap(txist[l][tw],txist[f][tw]);
							swap(tmp[l][tw],tmp[f][tw]);
							break;
						}
					}
				}
				while(true){
					rep(u,h) rep(v,w){
						if(tmp[u][v] == '.') continue;
						rep(l,2){
							int cnt = 1;
							int du = u, dv = v;
							while(true){
								du += dh[l];
								dv += dw[l];
								if(du >= h || dv >= w || tmp[u][v] != tmp[du][dv]) break;
								cnt++;
							}
							if(cnt >= n){
								for(int f = 0; f < cnt; f++){
									txist[u+dh[l]*f][v+dw[l]*f] = false;
								}
							}
						}
					}
					
					/*if(i == 2 && j == 2 && k == 1){
					rep(u,h){
						rep(v,w){
							cout << tmp[u][v];
						}
						cout << endl;
					}
					rep(u,h){
						rep(v,w){
							cout << txist[u][v];
						}
						cout << endl;
					}
					cout << endl;
					//}
*/
					bool end = true;
					rep(u,h) rep(v,w){
						if(txist[u][v] == false && tmp[u][v] != '.'){
							tmp[u][v] = '.';
							end = false;
						}
					}
					if(end){
						bool check = true;
						rep(u,h){
							rep(v,w){
								if(txist[u][v]){
									check = false;
									break;
								}
							}
							if(!check) break;
						}
						if(check){
							cout << "YES" << endl;
							return 0;
						}
						break;
					}
					for(int u = h-1; u >= 0; u--) rep(v,w){
						if(!txist[u][v]){
							int du = u;
							while(true){
								du--;
								if(du < 0) break;
								if(txist[du][v]){
									swap(tmp[du][v],tmp[u][v]);
									swap(txist[du][v],txist[u][v]);
									break;
								}
							}
						}
					}
				}
			}
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 1164