#include<iostream>
#include<vector>
using namespace std;

int h,w,n;
vector<string> s(50);

bool sim(void){
  int num = 0;
  for(int j=0;j<w;j++){
    for(int i=h-1;i>=0;i--){
      if(s[i][j] != '.'){
	num = 1;
	int d = 1;
	while(i+d<h && s[i+d][j] == '.'){swap(s[i+d][j],s[i+d-1][j]);d++;}
      }
    }
  }
  if(!num)return true;

  int u[50][50] = {0};

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j] != '.'){
	int d = 0;
	while(i+d<h && s[i][j] == s[i+d][j])d++;
	if(d>=n)for(int k=0;k<d;k++)u[i+k][j] = 1;

	d = 0;
	while(j+d<w && s[i][j] == s[i][j+d])d++;
	if(d>=n)for(int k=0;k<d;k++)u[i][j+k] = 1;
      }
    }
  }

  num = 0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(u[i][j]){s[i][j] = '.'; num++;}
  if(!num)return false;

  return sim();
}

int main(){
  cin >> h >> w >> n;
  for(int i=0;i<h;i++)cin >> s[i];
  vector<string> tmp = s;

  bool f = false;
  for(int i=0;i<h;i++){
    for(int j=1;j<w;j++){
      if(s[i][j-1] != s[i][j]){
	swap(s[i][j-1],s[i][j]);
	f = sim();
	if(f)break;
	s = tmp;
      }
    }
    if(f)break;
  }

  if(f)cout << "YES\n";
  else cout << "NO\n";
}