#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)

bool calc(vector<string> grid,int n)
{
	int h=grid.size(),w=grid[0].size();
	for(;;){
		rep(j,w) for(int i=h,k=h;i--;)
			if(grid[i][j]!='.')
				swap(grid[i][j],grid[--k][j]);
		
		bool update=false;
		vector<vector<int>> flg(h,vector<int>(w));
		rep(i,h) rep(j,w){
			if(grid[i][j]=='.') continue;
			bool f1=i+n<=h,f2=j+n<=w;
			rep(k,n) if(f1) f1&=grid[i+k][j]==grid[i][j];
			rep(k,n) if(f2) f2&=grid[i][j+k]==grid[i][j];
			update|=f1||f2;
			rep(k,n) if(f1) flg[i+k][j]=1;
			rep(k,n) if(f2) flg[i][j+k]=1;
		}
		rep(i,h) rep(j,w) if(flg[i][j]) grid[i][j]='.';
		if(!update) break;
	}
	return count(begin(grid),end(grid),string(w,'.'))==h;
}

int main()
{
	for(int h,w,n;cin>>h>>w>>n;){
		vector<string> grid(h);
		rep(i,h) cin>>grid[i];
		
		bool res=false;
		rep(i,h) rep(j,w-1){
			swap(grid[i][j],grid[i][j+1]);
			res|=calc(grid,n);
			swap(grid[i][j],grid[i][j+1]);
		}
		cout<<(res?"YES":"NO")<<endl;
	}
}