#include<bits/stdc++.h>
using namespace std;


int h, w, n;
vector<string> field;

void print(vector<string> &v){
    for(auto s: v)cout << s << endl;
}

vector<string> swap_block(int x1, int y1, int x2, int y2){
    vector<string> res = field;

    swap(res[y1][x1], res[y2][x2]);
    return res;
}

vector<string> erase(vector<string>& v){
    bool can_erase[40][40]={0};

    for(int i=0;i<h;++i){
        int cnt = 0;
        for(int j=0;j<w;++j){
            if(cnt == 0 && v[i][j] != '.' ||  j > 0 && v[i][j] == v[i][j-1])cnt++;
            else if(cnt > 0 && v[i][j] != v[i][j-1]){
                if(cnt >= n){
                    for(int k=1;k<=cnt;++k){
                        can_erase[i][j-k] = true;
                    }
                }
                cnt = (v[i][j] == '.' ? 0 : 1);
            }
        }
        if(cnt >= n){
            for(int k=1;k<=cnt;++k){
                can_erase[i][w-k] = true;
            }
        }
    }

    for(int j=0;j<w;++j){
        int cnt = 0;
        for(int i=0;i<h;++i){
            if(cnt == 0 && v[i][j] != '.' ||  i > 0 && v[i][j] == v[i-1][j])cnt++;
            else if(cnt > 0 && v[i][j] != v[i-1][j]){
                if(cnt >= n){
                    for(int k=1;k<=cnt;++k){
                        can_erase[i-k][j] = true;
                    }
                }
                cnt = (v[i][j] == '.' ? 0 : 1);
            }
        }
        if(cnt >= n){
            for(int k=1;k<=cnt;++k){
                can_erase[h-k][j] = true;
            }
        }
    }

    vector<string> res = v;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            if(can_erase[i][j])res[i][j] = '.';
        }
    }

    return res;
}

vector<string> drop(vector<string>& v){
    vector<string> res = v;

    for(int j=0;j<w;++j){
        bool empty = false;
        string s = "";
        for(int i=h-1;i>=0;--i){
            if(v[i][j] == '.')empty = true;
            if(empty && v[i][j] != '.'){
                s.push_back(v[i][j]);
            }
        }
        if(s.size() > 0){
            int idx = 0;
            bool flag = false;
            for(int i=0;i<h;++i){
                if(v[h-1-i][j] == '.')flag = true;
                if(!flag)continue;
                if(idx < s.size()){
                    res[h-1-i][j] = s[idx];
                    idx++;
                }else{
                    res[h-1-i][j] = '.';
                }
            }
        }
    }

    return res;
}

bool eq(vector<string>& v1, vector<string>& v2){
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            if(v1[i][j] != v2[i][j])return false;
        }
    }
    return true;
}

bool solve(){
    for(int i=0;i<h;++i){
        for(int j=0;j<w-1;++j){
            vector<string> v = swap_block(j,i,j+1,i);
            vector<string> v1 = drop(v);
            while(true){
                vector<string> v2 = erase(v1);
                vector<string> v3 = drop(v2);
                if(eq(v1, v3))break;
                v1 = v3;
            }

            bool ok = true;
            for(int i=0;i<h;++i){
                for(int j=0;j<w;++j){
                    if(v1[i][j] != '.'){
                        ok = false;
                        break;
                    }
                }
                if(!ok)break;
            }
//            cout << "swap: (" << j << "," << i << ") and (" << j+1 << "," << i << ")" << endl;
//            print(v1);
//            cout << endl;
            if(ok)return true;
        }
    }

    return false;
}

int main(){
    cin >>  h >> w >> n;
    for(int i=0;i<h;++i){
        string s;
        cin >> s;
        field.push_back(s);
    }
/*
    vector<string> v = swap_block(0,1,1,1);
    vector<string> v2 = erase(v);
    vector<string> v3 = drop(v2);
    print(v3);
*/

    cout << (solve() ? "YES" : "NO") << endl;

    return 0;
}



Measured memory_bytes: 3236