#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int H,W,N;
int dy[]={0,1},dx[]={1,0};
int pat[32][32];

int solve(vector<string> b){
    for(int i=H-1;i>=0;i--){
      rep(j,W){
	if(b[i][j]!='.') continue;
	int h=i;
	while(h>=0 && b[h][j]=='.') h--;
	if(h>=0){ b[i][j] = b[h][j]; b[h][j]='.';}
      }
    }
    //  rep(i,H) cout << b[i] << endl; cout << endl;
  int f=1;
  while(f){
    memset(pat, 0,sizeof(pat));
    f=0;
    rep(i,H) rep(j,W) rep(d,2){
      if(b[i][j]=='.') break;
      int y=i,x=j;
      int cnt=1;
      char color=b[y][x];
      while(1){
	y+=dy[d],x+=dx[d];
	if(y<0||y>=H||x<0||x>=W||b[y][x]!=color) break;
	cnt++;
      }
      if(cnt>=N){
	f=1;
	y=i,x=j;
	pat[y][x]=1;
	while(1){
	  y+=dy[d],x+=dx[d];
	  if(y<0||y>=H||x<0||x>=W||b[y][x]!=color) break;
	  pat[y][x] = 1;
	}
      }
    }
    rep(i,H) rep(j,W) if(pat[i][j]) b[i][j]='.';
    for(int i=H-1;i>=0;i--){
      rep(j,W){
	if(b[i][j]!='.') continue;
	int h=i;
	while(h>=0 && b[h][j]=='.') h--;
	if(h>=0){ b[i][j] = b[h][j]; b[h][j]='.';}
      }
    }
    //    rep(i,H) cout << b[i] << endl; cout << endl;
  }

  rep(i,H) rep(j,W) if(b[i][j]!='.') return 0;
  return 1;
}

int main(){
  cin >> H >> W >> N;
  vector<string>b(32);
  rep(i,H) cin >> b[i];

  rep(i,H) rep(j,W){
    int y=i+dy[0],x=j+dx[0];
    if(y<0||y>=H||x<0||x>=W||b[i][j]==b[y][x]) continue;
    swap(b[i][j], b[y][x]);
    if(solve(b)){
      cout << "YES\n";
      return 0;
    }
    swap(b[i][j], b[y][x]);
  }
  cout << "NO\n";
  return 0;
}