#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < int(n); ++i)
#define all(c) (c).begin(), (c).end()

bool Panel_de_PON(int h, int w, int n, vector<string> fields){
    for (;;) {
        for(int i = h - 2; i >= 0; --i) rep(j, w) {
            if (fields[i][j] == '.') continue;
            int k = i + 1;
            for(; k < h && fields[k][j] == '.'; ++k);
            swap(fields[i][j], fields[k - 1][j]);
        }
        vector<string> t = fields;
        rep(j, w) for (int i = 0; i < h;) {
            if (fields[i][j] == '.') { i++; continue; }
            int k = i;
            for (; i < h && fields[i][j] == fields[k][j]; ++i);
            if (i - k < n) continue;
            for (; k != i; ++k) t[k][j] = '.';
        }
        rep(i, h) for (int j = 0; j < w;) {
            if (fields[i][j] == '.') { j++; continue; }
            int k = j;
            for (; j < w && fields[i][j] == fields[i][k]; ++j);
            if (j - k < n) continue;
            for (; k != j; ++k) t[i][k] = '.';
        }
        fields.swap(t);
        if (all_of(all(fields), [&](string& s) { return count(all(s), '.') == w; })) return true;
        if (t == fields) break;
    }
    return false;
}

bool solve(int h, int w, int n, vector<string>& fields){
    for (int i = h - 1; i >= 0; --i) rep(j, w - 1) {
        if (fields[i][j] == fields[i][j + 1]) continue;
        swap(fields[i][j], fields[i][j + 1]);
        if (Panel_de_PON(h, w, n, fields)) return true;
        swap(fields[i][j], fields[i][j + 1]);
    }
    return false;
}

int main(){
    int h, w, n; cin >> h >> w >> n;
    vector<string> fields(h);
    for (auto& e : fields) cin >> e;
    cout << (solve(h, w, n, fields)? "YES": "NO") << endl;
    return 0;
}