#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    int h,w,n; cin >> h >> w >> n;
    vs s(h); rep(i,h) cin >> s[i];
    rep(i,h){
        rep(j,w-1){
            if(s[i][j] == s[i][j+1]) continue;
            vs t = s;
            swap(t[i][j], t[i][j+1]);
            while(1){
                rep(l,w){
                    int fall = 0;
                    for(int k=h-1; k>=0; k--){
                        if(t[k][l] == '.') fall++;
                        else{
                            if(fall){
                                t[k+fall][l] = t[k][l];
                                t[k][l] = '.';
                            }
                        }
                    }
                }
                vector<vb> v(h,vb(w,false));
                rep(k,h){
                    rep(l,w){
                        if(t[k][l] == '.') continue;
                        int cnt = 1;
                        char color = t[k][l];
                        REP(m,l+1,w){
                            if(t[k][m] == color) cnt++;
                            else break;
                        }
                        if(cnt >= n){
                            REP(m,l,w){
                                if(t[k][m] == color) v[k][m] = true;
                                else break;
                            }
                        }
                        cnt = 1;
                        REP(m,k+1,h){
                            if(t[m][l] == color) cnt++;
                            else break;
                        }
                        if(cnt >= n){
                            REP(m,k,h){
                                if(t[m][l] == color) v[m][l] = true;
                                else break;
                            }
                        }
                    }
                }
                bool f = false;
                bool exist = false;
                rep(k,h){
                    rep(l,w){
                        f = f || v[k][l];
                        if(v[k][l]) t[k][l] = '.';
                        else if(t[k][l] != '.') exist = true;
                    }
                }
                if(!f){
                    if(exist) break;
                    else{
                        puts("YES");
                        return 0;
                    }
                }
            }
        }
    }
    puts("NO");
}


Measured memory_bytes: 3224