#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define PRIME1 99999883
#define PRIME2 99999893
#define EPS 0.00000001
using namespace std;

struct Info{
	Info(int arg_row,int arg_col){
		row = arg_row;
		col = arg_col;
	}

	int row,col;
};

int H,W,N;

int main(){

	scanf("%d %d %d",&H,&W,&N);

	char table[H][W+1],work[H][W+1];

	for(int i = 0; i < H; i++){
		scanf("%s",table[i]);
	}

	bool FLG = false;
	int suc_count,count,tmp;
	char ch;
	stack<Info> S;

	for(int i = 0; i < H; i++){
		for(int k = 0; k < W-1; k++){

			for(int a = 0; a < H; a++){
				for(int b = 0; b < W; b++){
					work[a][b] = table[a][b];
				}
			}

			swap(work[i][k],work[i][k+1]);

			for(int a = H-1; a >= 1; a--){
				for(int b = 0; b < W; b++){
					if(work[a][b] != '.')continue;

					for(tmp = a-1; tmp >= 0; tmp--){
						if(work[tmp][b] != '.'){
							break;
						}
					}
					if(tmp >= 0){
						work[a][b] = work[tmp][b];
						work[tmp][b] = '.';
					}
				}
			}

			while(true){

				for(int a = 0; a <= H-N; a++){
					for(int b = 0; b < W; b++){
						if(work[a][b] == '.')continue;

						ch = work[a][b];
						suc_count = 1;
						for(int c = a+1; c <= H-1;c++){
							if(work[c][b] != ch){
								break;
							}else{
								suc_count++;
							}
						}

						if(suc_count >= N){
							for(int c = 0; c < suc_count;c++){
								S.push(Info(a+c,b));
							}
						}

						if(a+suc_count <= H-1 && work[a+suc_count][b] != '.'){
							tmp = a + suc_count;
							ch = work[tmp][b];
							suc_count = 1;
							for(int c = tmp+1;c <= H-1; c++){
								if(work[c][b] != ch){
									break;
								}else{
									suc_count++;
								}
							}

							if(suc_count >= N){

								for(int c = 0; c < suc_count;c++){
									S.push(Info(tmp+c,b));
								}
							}
						}
					}
				}

				for(int a = 0; a < H; a++){
					for(int b = 0; b <= W-N; b++){
						if(work[a][b] == '.')continue;

						ch = work[a][b];
						suc_count = 1;
						for(int c = b+1; c <= W-1;c++){
							if(work[a][c] != ch){
								break;
							}else{
								suc_count++;
							}
						}

						if(suc_count >= N){

							for(int c = 0; c < suc_count;c++){
								S.push(Info(a,b+c));
							}
						}

						if(b+suc_count <= W-1 && work[a][b+suc_count] != '.'){

							tmp = b+suc_count;
							ch = work[a][tmp];
							suc_count = 1;
							for(int c = tmp+1; c <= W-1;c++){
								if(work[a][c] != ch){
									break;
								}else{
									suc_count++;
								}
							}

							if(suc_count >= N){

								for(int c = 0; c < suc_count;c++){
									S.push(Info(a,tmp+c));
								}
							}
						}
					}
				}

				if(S.empty())break;

				while(!S.empty()){
					work[S.top().row][S.top().col] = '.';
					S.pop();
				}

				for(int a = H-1; a >= 1; a--){
					for(int b = 0; b < W; b++){
						if(work[a][b] != '.')continue;

						for(tmp = a-1; tmp >= 0; tmp--){
							if(work[tmp][b] != '.'){
								break;
							}
						}
						if(tmp >= 0){
							work[a][b] = work[tmp][b];
							work[tmp][b] = '.';
						}
					}
				}

			}


			count = 0;
			for(int a = 0; a < H; a++){
				for(int b = 0; b < W; b++){
					if(work[a][b] != '.'){
						count++;
						break;
					}
				}
				if(count != 0)break;
			}

			if(count == 0){
				FLG = true;
				break;
			}
		}
		if(FLG)break;
	}

	if(FLG){
		printf("YES\n");
	}else{
		printf("NO\n");
	}

    return 0;
}

Measured memory_bytes: 3172