//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int H, W, N;
  cin>>H>>W>>N;
	
  vector<string> tab(H+1);
  REP(y,H){
	cin >> tab[y];
	tab[y] += '?';
  }
  tab[H] = string(W+1, '?');

  bool ans = false;
  for(int sy=0;sy<H;++sy)
	for(int sx=0;sx<W-1;++sx){
	  vector<string> tmp = tab;
	  swap(tmp[sy][sx], tmp[sy][sx+1]);

	  REP(x,W){
		int ty = H-1;
		for(int y=H-1;y>=0;--y)
		  if(tmp[y][x] != '.'){
			swap(tmp[y][x], tmp[ty][x]);
			--ty;
		  }
	  }


	  bool updated = true;
	  while(updated){
		updated = false;
		vector< vector<bool> > del(H, vector<bool>(W, false));
		for(int y=0;y<H;++y){
		  char prv = 0;
		  int cnt = 0;
		  for(int x=0;x<=W;++x){
			if(prv == tmp[y][x] && prv != '.') ++cnt;
			else{
			  if(cnt >= N)
				for(int tx=x-1;tx>=0 && cnt>0;--tx,--cnt)
				  del[y][tx] = true;
			  prv = tmp[y][x];
			  cnt = 1;
			}
		  }
		}

		for(int x=0;x<W;++x){
		  char prv = 0;
		  int cnt = 0;
		  for(int y=0;y<=H;++y){
			if(prv == tmp[y][x] && prv != '.') ++cnt;
			else{
			  if(cnt >= N)
				for(int ty=y-1;ty>=0 && cnt>0;--ty,--cnt)
				  del[ty][x] = true;
			  prv = tmp[y][x];
			  cnt = 1;
			}
		  }
		}

		REP(y,H) REP(x,W) if(del[y][x]) updated = true, tmp[y][x] = '.';
		REP(x,W){
		  int ty = H-1;
		  for(int y=H-1;y>=0;--y)
			if(tmp[y][x] != '.'){
			  swap(tmp[y][x], tmp[ty][x]);
			  --ty;
			}
		}
	  }

	  bool left = false;
	  REP(y,H) REP(x,W)
		if(tmp[y][x] != '.') left = true;
	  if(!left){
		ans = true;
		break;
	  }
	}

  cout << (ans? "YES": "NO") << endl;
  
  return 0;
}