#include <bits/stdc++.h>
using namespace std;

int H, W, N;

void show(vector<vector<char>> field) {
    for (auto i : field) {
        for (auto j : i) {
            cout << j;
        }
        cout << endl;
    }
    cout << "---------------" << endl;
}
void show(vector<vector<bool>> field) {
    for (auto i : field) {
        for (auto j : i) {
            cout << j;
        }
        cout << endl;
    }
    cout << "---------------" << endl;
}

void slide(vector<vector<char>>& field) {
    for (int i = 1; i < field[0].size() - 1; i++) {
        int cnt = 0;
        for (int j = field.size() - 2; j > 0; j--) {
            // cout << "i: " << i << "j: " << j << endl;
            if (field[j][i] == '.')
                cnt++;
            else if (cnt != 0) {
                field[j + cnt][i] = field[j][i];
                field[j][i] = '.';
            }
        }
    }
}

bool broken(vector<vector<char>> field, pair<int, int> move, int ny, int nx) {
    char tmp = field[move.first][move.second];
    field[move.first][move.second] = field[ny][nx];
    field[ny][nx] = tmp;
    // 以上入れ替え
    bool flag = true;
    vector<vector<bool>> fField(field.size(), vector<bool>(field[0].size(), false));
    while (flag) {
        flag = false;
        slide(field);
        // 消せるか確認する
        for (int i = 1; i < field.size() - 1; i++) {
            for (int j = 1; j < field[i].size() - 1; j++) {
                if (field[i][j] == '.') continue;
                // if (fField[i][j]) continue;
                // 横の処理
                int cnt = 0;
                for (int k = j; k < field[i].size() - 1; k++) {
                    if (field[i][j] == field[i][k])
                        cnt++;
                    else
                        break;
                }
                if (cnt >= N) {
                    for (int k = j; k < j + cnt; k++) {
                        fField[i][k] = true;
                        flag = true;
                    }
                }
                // 縦の処理
                cnt = 0;
                for (int k = i; k < field.size() - 1; k++) {
                    if (field[i][j] == field[k][j])
                        cnt++;
                    else
                        break;
                }
                if (cnt >= N) {
                    for (int k = i; k < i + cnt; k++) {
                        fField[k][j] = true;
                        flag = true;
                    }
                }
            }
        }
        // show(fField);
        // 消去の作業
        for (int i = 1; i < fField.size() - 1; i++) {
            for (int j = 1; j < fField[i].size() - 1; j++) {
                if (fField[i][j]) {
                    field[i][j] = '.';
                    fField[i][j] = false;
                }
            }
        }
    }
    slide(field);
    // 一番下を確認して.しかなければtrue
    for (int i = 1; i < field[0].size() - 1; i++) {
        if (field[field.size() - 2][i] != '.') return false;
    }
    return true;
}

bool solve(vector<vector<char>> field) {
    vector<pair<int, int>> canMove;
    for (int i = 1; i < field.size() - 1; i++) {
        for (int j = 1; j < field[i].size() - 1; j++) {
            if (field[i][j] != '.') {
                // cout << i << " " << j << endl;
                canMove.push_back(make_pair(i, j));
            }
        }
    }
    vector<int> dx = {-1, 1};
    vector<int> dy = {0, 0};
    for (int i = 0; i < canMove.size(); i++) {
        for (int j = 0; j < 2; j++) {
            int nx = dx[j] + canMove[i].second;
            int ny = dy[j] + canMove[i].first;
            if (field[ny][nx] == '#') continue;
            // cout << ny << " " << nx << endl;
            if (broken(field, canMove[i], ny, nx)) return true;
        }
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W >> N;
    vector<vector<char>> field(H + 2, vector<char>(W + 2, '#'));
    for (int i = 1; i < H + 1; i++) {
        for (int j = 1; j < W + 1; j++) {
            cin >> field[i][j];
        }
    }
    if (solve(field))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}


Measured memory_bytes: 3232