#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 300010;

int h, w, n;

void drop(vector<string> &a){
    rep(j, w){
        vector<char> tmp;
        rrep(i, h)if(a[i][j] != '.') tmp.push_back(a[i][j]);
        rep(i, h) a[i][j] = '.';
        rep(i, tmp.size()) a[h-1-i][j] = tmp[i];
    }
}

vector<string> f(vector<string> &a){
    while(true){
        vector<pair<pii, int>> tate, yoko;
        rep(j, w){
            int l = 0;
            while(l < h){
                if(a[l][j] == '.'){
                    ++l;
                    continue;
                }
                int r = l;
                while(r < h && a[l][j] == a[r][j]) ++r;
                if(r-l >= n) tate.push_back({{l, j}, r-l});
                l = r;
            }
        }

        rep(i, h){
            int l = 0;
            while(l < w){
                if(a[i][l] == '.'){
                    ++l;
                    continue;
                }
                int r = l;
                while(r < w && a[i][l] == a[i][r]) ++r;
                if(r-l >= n) yoko.push_back({{i, l}, r-l});
                l = r;
            }
        }

        if(tate.empty() && yoko.empty()) break;

        for(auto &p: tate){
            rep(i, p.se) a[p.fi.fi+i][p.fi.se] = '.';
        }
        for(auto &p: yoko){
            rep(i, p.se) a[p.fi.fi][p.fi.se+i] = '.';
        }

        drop(a);
    }
    return a;
}

bool check(vector<string> &a){
    rep(i, h)rep(j, w)if(a[i][j] != '.') return false;
    return true;
}

int main(){
    scanf("%d%d%d", &h, &w, &n);
    vector<string> c(h);
    rep(i, h) cin >> c[i];

    rep(i, h)rep(j, w-1){
        vector<string> a = c;
        swap(a[i][j], a[i][j+1]);
        drop(a);

        a = f(a);
        if(check(a)){
            puts("YES");
            return 0;
        }
    }
    puts("NO");
}
