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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pll> vp;
typedef vector<ll> vll;

const int S = 31;

int H, W, N;
char board[S][S];
char s1[S][S];
char s2[S][S];

bool noBlocks() {
    rep(i, H) {
        rep(j, W) {
            if (s2[i][j] != '.') return false;
        }
    }
    return true;
}

bool change(int r1, int c1, int r2, int c2) {
    if (board[r1][c1] == board[r2][c2]) return false;

    rep(i, H + 1) rep(j, W + 1) s1[i][j] = board[i][j];
    swap(s1[r1][c1], s1[r2][c2]);

    // cout << r1 << " " << c1 << " " << r2 << " " << c2 << endl;
    while (true) {
        // dropping
        rep(j, W) {
            for (int i = H-1; i > 0; i--) {
                if (s1[i][j] == '.') {
                    for (int k = i-1; k >= 0; k--) {
                        if (s1[k][j] != '.') {
                            swap(s1[i][j], s1[k][j]);
                            break;
                        }
                     }
                 }
            }
        }

        rep(i, H + 1) rep(j, W + 1) s2[i][j] = s1[i][j];

        bool erased = false;

        // horizontal erase
        int cnt = 1;
        rep(i, H) {
            rep(j, W) {
                if (s1[i][j] != '.' && s1[i][j] == s1[i][j + 1]) {
                    cnt++;
                } else {
                    if (cnt >= N) {
                        erased = true;
                        for (int k = j; k > j - cnt; k--) {
                            s2[i][k] = '.';
                        }
                    }
                    cnt = 1;
                }
            }
        }

        // vertical erase
        cnt = 1;
        rep(j, W) {
            rep(i, H) {
                if (s1[i][j] != '.' && s1[i][j] == s1[i + 1][j]) {
                    cnt++;
                } else {
                    if (cnt >= N) {
                        erased = true;
                        for (int k = i; k > i - cnt; k--) {
                            s2[k][j] = '.';
                        }
                    }
                    cnt = 1;
                }
            }
        }

        if (!erased) {
            // rep(i, H) {
            //     rep(j, W) {
            //         cout << s1[i][j];
            //     }
            //     cout << endl;
            // }
            // cout << endl;
            return false;
        }
        if (noBlocks()) return true;

        rep(i, H) rep(j, W) s1[i][j] = s2[i][j];


    }
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    cin >> H >> W >> N;
    rep(i, H) {
        string t;
        cin >> t;
        rep(j, W) {
            board[i][j] = t[j];
        }
        board[i][W] = '.';
    }
    rep(j, W) board[H][j] = '.';

    if (N > H && N > W) {
        cout << "NO" << endl;
        return 0;
    }

    rep(i, H) {
        rep(j, W - 1) {
            if (change(i, j, i, j + 1)) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 3188