#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int h, w, n;
    vector<vector<char> > field;
    vector<vector<char> > field2;

    void input() {
        cin >> h >> w >> n;
        field.resize(h, vector<char>(w));
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                cin >> field[i][j];
            }
        }
    }

    //一個も消せなかったらfalseを返す

    void rakka() {
        for (int c = 0; c < w; ++c) {
            int R = h - 1;
            for (int r = h - 1; r >= 0; --r) {
                if (field2[r][c] != '.') {
                    char ch = field2[r][c];
                    field2[r][c] = '.';
                    field2[R][c] = ch;
                    R--;
                }
            }
        }
    }

    bool del() {
        vector<vector<bool> > flag(h, vector<bool>(w, false)); //消されるやつ

        for (int i = 0; i < h; ++i) {
            for (int l = 0, r = 0; l < w;) {
                while (r < w && field2[i][l] == field2[i][r]) {
                    r++;
                }
                if (r - l >= n) {
                    for (int j = l; j < r; ++j) {
                        flag[i][j] = true;
                    }
                }
                l = r;
            }
        }

        for (int i = 0; i < w; ++i) {
            for (int u = 0, d = 0; u < h;) {
                while (d < h && field2[u][i] == field2[d][i]) {
                    d++;
                }
                if (d - u >= n) {
                    for (int j = u; j < d; ++j) {
                        flag[j][i] = true;
                    }
                }
                u = d;
            }
        }

        bool ret = false;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if (field2[i][j] != '.' && flag[i][j]) {
                    ret = true;
                    field2[i][j] = '.';
                }
            }
        }
        rakka();
        return ret;
    }

    bool check(int r, int c, int dr, int dc) {
        if (r + dr >= h || c + dc >= w) return false;
        field2 = field;
        swap(field2[r][c], field2[r + dr][c + dc]);
        rakka();
        while (del()) {

        }

        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if (field2[i][j] != '.') return false;
            }
        }
        return true;
    }


    void solve() {
        input();

//        bool tmp = check(1, 0, 0, 1);

        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                bool tmp;
                tmp = check(i, j, 0, 1);
                if (tmp) {
                    cout << "YES" << endl;
                    return;
                }


//                tmp = check(i, j, 1, 0);
//                if (tmp) {
//                    cout << "YES" << endl;
//                    return;
//                }

            }
        }

        cout << "NO" << endl;


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}



Measured memory_bytes: 3228