#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

ll h,w,n;
char t[40][40];

int check(){
	int ret=0;
	rep(i,0,h)rep(j,0,w-n+1)if(t[i][j]!='.'){
		int flag=1;
		rep(k,0,n)flag&=(t[i][j]&31)==(t[i][j+k]&31);
		if(flag){
			ret=1;
			rep(k,0,n)t[i][j+k]|=32;
		}
	}
	rep(i,0,h-n+1)rep(j,0,w)if(t[i][j]!='.'){
		int flag=1;
		rep(k,0,n)flag&=(t[i][j]&31)==(t[i+k][j]&31);
		if(flag){
			ret=1;
			rep(k,0,n)t[i+k][j]|=32;
		}
	}
	return ret;
}

void f(){
	do{
		rep(i,0,h)rep(j,0,w)if(t[i][j]&32)t[i][j]=' ';
		rep(j,0,w){
			int cnt=0;
			rep(i,0,h)if(t[i][j]!=' ')t[cnt++][j]=t[i][j];
			rep(i,cnt,h)t[i][j]='.';
		}
	}while(check());
	int flag=1;
	rep(i,0,h)rep(j,0,w)flag&=t[i][j]=='.';
	if(flag){
		puts("YES");
		exit(0);
	}
}

int main(){
	char s[40][40];
	scanf("%lld%lld%lld",&h,&w,&n);
	rep(i,0,h)scanf(" %s",s[h-1-i]);
	rep(i,0,h-1)rep(j,0,w-1){
		if(s[i][j]!=s[i][j+1]){
			memcpy(t,s,1600);
			char c=t[i][j];
			t[i][j]=t[i][j+1];
			t[i][j+1]=c;
			f();
		}
	}
	puts("NO");
}
