#include <utility> // pair make_pair
using std::swap; // c++11
using std::pair;
using std::make_pair;
#include <tuple> // tuple(c++11) make_tuple(c++11)
using std::tuple; // get<address>(variable)
using std::make_tuple;
#include <string> // string stoi(c++11) stoll(c++11) to_string(c++11)
using std::string;
using std::stoi;
using std::stoll;
using std::to_string;
#include <queue> // queue priority_queue
using std::queue;
using std::priority_queue;
#include <stack> // stack
using std::stack;
#include <vector> // vector
using std::vector;
#include <map> // map
using std::map;
#include <set> // set
using std::set; // insert erase find count
#include <algorithm> // min max
using std::sort;
using std::lower_bound; // iterator,  >=
using std::upper_bound; // iterator,  >
using std::min;
using std::max;
using std::min_element; // iterator
using std::max_element; // iterator
#include <complex> // complex
using std::complex; // real imag
#include <iostream> // cin cout
using std::cin;
using std::cout;
using std::endl;
#include <iomanip> // setprecision fixed(manipulator)
using std::setprecision;
using std::fixed;
#include <cmath>
#include <cstdio>

#define lli long long int
#define INF (int)1e09
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define EFOR(i, m, n) for (int i = m; i <= n; i++)
#define RFOR(i, m, n) for (int i = m; i > n; i--)
#define REFOR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort((v).begin(), (v).end()) // sort vector
typedef pair<int, int> PI;
typedef tuple<int, int, int> TI;
template <typename T> using Vec = vector<T>; // c++11


int h;
int w;
int n;
int dy[4] = {0, 0, -1, 1};
int dx[4] = {-1, 1, 0, 0};

int count (Vec<Vec<char> > table, int i, int j, int dir, char target); 
bool total(Vec<Vec<char> > table, int i, int j, int dir, int n); 
bool del (Vec<Vec<char> > &table, int n); 
void drop (Vec<Vec<char> > &table); 

void print (Vec<Vec<char> > table) {
    FOR (i, 0, h + 2) {
        FOR (j, 0, w + 2) {
            cout << table[i][j];
        }
        cout << endl;
    }
    cout << endl;
    return;
}

int main(void) {
    cin >> h >> w >> n;
    Vec<Vec<char> > table(h + 2, Vec<char>(w + 2, '#'));
    FOR (i, 0, h) {
        FOR (j, 0, w) {
            cin >> table[i + 1][j + 1];
        }
    }

    FOR (i, 1, h + 1) {
        FOR (j, 1, w + 1) {
            // ???,?????¨???????????????????????????????????¨??¨?¶????????????????
            if (total(table, i, j, 1, n) == true) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}

int count (Vec<Vec<char> > table, int i, int j, int dir, char target) {
    int bai = 1;
    while (1) {
        char new_target = table[i + bai * dy[dir]][j + bai * dx[dir]];
        if (new_target == target) {
            bai++;
        } else {
            break;
        }
    }
    return bai - 1;
}

bool total(Vec<Vec<char> > table, int i, int j, int dir, int n) {
    //cout << "I = " << i << ", J = " << j << endl;
    char now = table[i][j];
    char target = table[i + dy[dir]][j + dx[dir]];
    if (now == target || target == '#') {
        return false;
    }
    swap(table[i][j], table[i + dy[dir]][j + dx[dir]]);
    bool check;
    while(1) {
        drop(table);
        check = del(table, n); // type bool
        if (check == false) {
            break;
        }
    }

    FOR (p, 1, h + 1) {
        FOR (q, 1, w + 1) {
            if (table[p][q] != '.') {
                return false;
            }
        }
    }
    return true;
}

bool del (Vec<Vec<char> >& table, int n) {
    bool check = false;
    Vec<Vec<char> > copy = table;
    FOR (i, 1, h + 1) {
        FOR (j, 1, w + 1) {
            char target = copy[i][j];
            if (target != '.') {
                if (count (copy, i, j, 0, target) + count (copy, i, j, 1, target) + 1 >= n
                        || count (copy, i, j, 2, target) + count (copy, i, j, 3, target) + 1 >= n) {
                    // n + 1??¨??????????????????????????????????????????
                    table[i][j] = '.';
                    check = true;
                }
            }
        }
    }
    return check;
}

void drop (Vec<Vec<char> >& table) {
    while (1) {
        bool cont = false;
        RFOR (i, h, 1) {
            RFOR (j, w, 0) {
                if (table[i][j] == '.') {
                    if (table[i - 1][j] != '.') {
                        cont = true;
                        table[i][j] = table[i - 1][j];
                        table[i - 1][j] = '.';
                    }
                }
            }
        }
        if (cont == false) {
            break;
        }
    }
    return;
}

Measured memory_bytes: 3180