#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

int H, W, N;

char gfield[30][32];
char field[30][32];
char next_field[30][32];

void copy_field(char f[30][32], char g[30][32]) {
    for (int j = 0; j < 30; ++j) {
        for (int k = 0; k < 32; ++k) {
            g[j][k] = f[j][k];
        }
    }
}

bool check () {
    bool updated = true;
    
    while (updated) {
        updated = false;

        // drop
        for(int n = 0; n < H; ++n) {
            for(int j = H - 1; j > 0; --j) {
                for(int k = 0; k < W; ++k) {
                    if (field[j][k] == '.') {
                        swap(field[j][k], field[j-1][k]);
                    }
                }
            }
        }

        copy_field(field, next_field);

        // row
        for (int j = 0; j < H; ++j) {
            for (int k = 0; k < W; ++k) {
                if (field[j][k] == '.') continue;

                int l = 1;
                for (;k + l < W; ++l) {
                    if (field[j][k] != field[j][k + l]) {
                        break;
                    }
                }
                if (l >= N) {
                    updated = true;
                    for (int x = k; x < k + l; ++x) {
                        next_field[j][x] = '.';
                    }
                }
            }
        }

        // column
        for (int j = 0; j < H; ++j) {
            for (int k = 0; k < W; ++k) {
                if (field[j][k] == '.') continue;

                int l = 1;
                for (;j + l < H; ++l) {
                    if (field[j][k] != field[j + l][k]) {
                        break;
                    }
                }
                if (l >= N) {
                    updated = true;
                    for (int x = j; x < j + l; ++x) {
                        next_field[x][k] = '.';
                    }
                }
            }
        }

        copy_field(next_field, field);

    }

    for (int j = 0; j < H; ++j) {
        for(int k = 0; k < W; ++k) {
            if(field[j][k] != '.') {
                return false;
            }
        }
    }
    return true;
}

string solve() {
    for (int j = 0; j < H; ++j) {
        for(int k = 0; k < W-1; ++k) {
            copy_field(gfield, field);

            swap(field[j][k], field[j][k + 1]);

            if(check()) {
                return "YES";
            }
        }
    }
    return "NO";
}

int main() {
    cin >> H >> W >> N;
    for (int j = 0; j < H; ++j) {
        cin >> gfield[j];
    }
    cout << solve() << endl;
    return 0;
}