#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

void disp(vector<string> s){
    for(int i=0;i<s.size();i++){
        cerr << s[i] << endl;
    }
    cerr << endl;
}
int main(){
    int h,w,n;
    cin >> h >> w >> n;
    vector<string> field(h);
    for(int i=0;i<h;i++){
        cin >> field[i];
    }

    bool anyok = false;
    for(int choy=0;choy<h;choy++){
        for(int chox=0;chox<w;chox++){
            if(field[choy][chox] != '.'){
                for(int i=0;i<1;i++){
                    int ty=choy+dy[i];
                    int tx=chox+dx[i];
                    if(tx < 0 or tx >= w or ty < 0 or ty >= h) continue;

                    vector<string> myfield = field;
                    swap(myfield[choy][chox],myfield[ty][tx]);

                    bool update = true;
                    while(update){
                        //disp(myfield);
                        update = false;
                        for(int y=h-1;y>=0;y--){
                            for(int x=0;x<w;x++){
                                if(myfield[y][x] != '.'){
                                    int newp = y;
                                    for(int k=y+1;k<h;k++){
                                        if(myfield[k][x] != '.') break;
                                        newp = k;
                                        //update = true;
                                    }
                                    swap(myfield[y][x],myfield[newp][x]);
                                }
                            }
                        }
                        vector<string> next = myfield;
                        for(int y=0;y<h;y++){
                            for(int x=0;x<w;x++){
                                char c = myfield[y][x];
                                if(c == '.') continue;
                                {
                                    int ren = 0;
                                    for(int ddy=0;;ddy++){
                                        if(y + ddy >= h or myfield[y+ddy][x] != c){
                                            break;
                                        }
                                        ren++;
                                    }
                                    if(ren >= n){
                                        for(int ddy=0;ddy<ren;ddy++){
                                            next[y+ddy][x] = '.';
                                        }
                                        update = true;
                                    }
                                }
                                {
                                    int ren = 0;
                                    for(int ddx=0;;ddx++){
                                        if(x + ddx >= w or myfield[y][x+ddx] != c){
                                            break;
                                        }
                                        ren++;
                                    }
                                    if(ren >= n){
                                        for(int ddx=0;ddx<ren;ddx++){
                                            next[y][x+ddx] = '.';
                                        }
                                        update = true;
                                    }
                                }
                            }
                        }
                        myfield = next;
                    }

                    bool ok = true;
                    for(int i=0;i<h;i++){
                        for(int j=0;j<w;j++){
                            if(myfield[i][j] != '.') ok = false;
                        }
                    }
                    anyok = anyok or ok;
                }
            }
        }
    }
    if(anyok){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1212