#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define whole(xs) xs.begin(), xs.end()

ostream& operator<<(ostream& os, const vector<string>& v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << endl;
    }
    return os;
}

int H, W, N;
#define MH 30
#define MW 30
vector<string> F;

const int dy[] = {0, 1, 0, -1},
          dx[] = {1, 0, -1, 0};
void Drop(vector<string>& F1);
void DeleteMarked(vector<string>& F1, bool Mark[MH][MW]) {
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (Mark[y][x]) {
                F1[y][x] = '.';
            }
        }
    }
    Drop(F1);
}

void Drop(vector<string>& F1) {
    bool Changed = true;
    while (Changed) {
        Changed = false;
        for (int y = 0; y < H; y++) {
            for (int x = 0; x < W; x++) {
                if (!isalpha(F1[y][x])) continue;
                if (y + 1 < H && F1[y + 1][x] == '.') {
                    Changed = true;
                    swap(F1[y][x], F1[y + 1][x]);
                }
            }
        }
    }
}

bool Finished(const vector<string>& F1);
bool Check(vector<string> F1) {
    if (Finished(F1)) return true;
    Drop(F1);
    bool Mark[MH][MW];
    memset(Mark, 0, sizeof(Mark));
    for (int y = 0; y < H; y++) {
        char prev = F1[y][0];
        int n = 1;
        for (int x = 1; x <= W; x++) {
            if (x < W && F1[y][x] == prev) {
                n++;
            } else {
                if (n >= N) {
                    for (int x1 = x - 1; x1 >= x - n; x1--) {
                        Mark[y][x1] = true;
                    }
                }
                if (x < W) {
                    n = 1;
                    prev = F1[y][x];
                }
            }
        }
    }
    for (int x = 0; x < W; x++) {
        char prev = F1[0][x];
        int n = 1;
        for (int y = 1; y <= H; y++) {
            if (y < H && F1[y][x] == prev) {
                n++;
            } else {
                if (n >= N) {
                    for (int y1 = y - 1; y1 >= y - n; y1--) {
                        Mark[y1][x] = true;
                    }
                }
                if (y < H) {
                    n = 1;
                    prev = F1[y][x];
                }
            }
        }
    }
    vector<string> prevF1 = F1;
    /*
    cerr << "before" << endl << prevF1 << endl;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) 
            cerr << Mark[i][j] << " ";
        cerr << endl;
    }
    cerr << "after" << endl << F1 << endl;
    */
    DeleteMarked(F1, Mark);
    if (F1 == prevF1) return false;
    return Check(F1);
}

bool Finished(const vector<string>& F1) {
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (F1[y][x] != '.') {
                return false;
            }
        }
    }
    return true;
}

bool solve() {
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (!isalpha(F[y][x])) continue;
            for (int d = -1; d <= 1; d += 2) {
                int ny = y,
                    nx = x + d;
                if (ny < 0 || ny >= H) continue;
                if (nx < 0 || nx >= W) continue;
                //if (!isalpha(F[ny][nx])) continue;
                swap(F[y][x], F[ny][nx]);
                if (Check(F)) {
                    return true;
                }
                swap(F[ny][nx], F[y][x]);
            }
        }
    }
    return false;
}

void input() {
    cin >> H >> W >> N;
    F.resize(H);
    for (int i = 0; i < H; i++) {
        cin >> F[i];
    }
}

int main() {
    input(); 
    cout << (solve() ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 1388