#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int H, W, N;

void drop(vector<string>& v) {
    for(int w=0; w<W; ++w) {
        for(int h=0; h<H; ++h) {
            if(v[h][w] == '.') {
                for(int h2=h+1; h2<H; ++h2) {
                    if(v[h2][w] != '.') {
                        v[h][w] = v[h2][w];
                        v[h2][w] = '.';
                        break;
                    }
                }
            }
        }
    }
}
bool solve(vector<string>& v) {
    bool update = true;
    vector<vector<bool>> used(H, vector<bool>(W, false));
    drop(v);
    while(update) {
        update = false;
        for(int h=0; h<H; ++h) {
            char prev = ' ';
            int cnt = 1;
            for(int w=0; w<W; ++w) {
                if(prev == v[h][w] && v[h][w] != '.') {
                    cnt++;
                } else {
                    if(cnt >= N) {
                        fill(used[h].begin() + w - cnt, used[h].begin() + w, true);
                        update = true;
                    }
                    cnt = 1;
                }
                prev = v[h][w];
            }
            if(cnt >= N) {
                fill(used[h].end() - cnt, used[h].end(), true);
                update = true;
            }
        }
        for(int w=0; w<W; ++w) {
            char prev = ' ';
            int cnt = 1;
            for(int h=0; h<H; ++h) {
                if(prev == v[h][w] && v[h][w] != '.') {
                    cnt++;
                } else {
                    if(cnt >= N) {
                        for(int k=h-cnt; k<h; ++k) {
                            used[k][w] = true;
                        }
                        update = true;
                    }
                    cnt = 1;
                }
                prev = v[h][w];
            }
            if(cnt >= N) {
                for(int k=H-cnt; k<H; ++k) {
                    used[k][w] = true;
                }
                update = true;
                cnt = 1;
            }
        }

        for(int h=0; h<H; ++h) {
            for(int w=0; w<W; ++w) {
                if(used[h][w]) {
                    v[h][w] = '.';
                }
                used[h][w] = false;
            }
        }

        drop(v);
    }

    for(int h=0; h<H; ++h) {
        for(int w=0; w<W; ++w) {
            if(v[h][w] != '.') {
                return false;
            }
        }
    }
    return true;
}

int main() {
    cin >> H >> W >> N;
    vector<string> v(H);
    for(int i=0; i<H; ++i) {
        cin >> v[i];
    }
    reverse(v.begin(), v.end());

    for(int y=0; y<H; ++y) {
        for(int x=0; x<W-1; ++x) {
            if(v[y][x] != v[y][x+1]) {
                auto v2 = v;
                v2[y][x] = v[y][x+1];
                v2[y][x+1] = v[y][x];
                //cout << endl;
                //for(auto& x : v2) {
                //    cout << x << endl;
                //}
                //cout << endl;
                if(solve(v2)) {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 3220