#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
//#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m,q;
	cin>>n>>m>>q;
	vs tmp(m,"");
	rep(i,n)rep(j,m){
		char c;cin>>c;
		tmp[j]=c+tmp[j];
	}
//	rep(i,m)cout<<in[i]<<endl;
	bool h=false;
	rep(x,m-1)rep(y,n){
		vs in=tmp;
		swap(in[x][y],in[x+1][y]);
		rep(i,m){
			string t="";
			rep(j,n)if(in[i][j]!='.')t+=in[i][j];
			while(t.size()!=n)t+=".";
			in[i]=t;
		}
		while(1){
			vvi to(m,vi(n));
			rep(i,m)rep(j,n-1)if(in[i][j]!='.'){
				int t=j;
				while(t+1<n&&in[i][t]==in[i][t+1])t++;
				if(t-j+1>=q)loop(k,j,t+1)to[i][k]=true;
				j=t;
			}
			rep(i,n)rep(j,m-1)if(in[j][i]!='.'){
				int t=j;
				while(t+1<m&&in[t][i]==in[t+1][i])t++;
				if(t-j+1>=q)loop(k,j,t+1)to[k][i]=true;
				j=t;
			}
			bool he=false;
			rep(i,m){
				string t="";
				rep(j,n)if(!to[i][j])t+=in[i][j];
				while(t.size()!=n)t+=".";
				if(in[i]!=t)he=true;
				in[i]=t;
			}
			if(!he)break;
		}
		bool H=true;
		rep(i,m)rep(j,n)if(in[i][j]!='.')H=false;
		if(H)h=true;
	}
	if(h)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}