#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int H, W, N;
char Field[35][35];
int kieru[35][35];

int solve(void) {
    char field[35][35];
    for (int i = 0; i <= H+1; i++) {
        for (int j = 0; j <= W+1; j++) {
            if (i == 0 || j == 0 || i == H+1 || j == W+1) {
                field[i][j] = '#';
            } else {
                field[i][j] = Field[i][j];
            }
        }
    }

    int flag = 2;
    while (0 < flag) {
        memset(kieru, 0, sizeof(kieru));
        if (flag == 2) {
            flag--;
            goto HELL;
        }
        flag--;
        for (int i = 1; i <= H; i++) {
            char crtColor = field[i][1];
            int cnt = 0;
            for (int j = 1; j <= W+1; j++) {
                if (crtColor == field[i][j] && crtColor != '.') {
                    cnt++;
                } else {
                    if (N <= cnt) {
                        for (int k = j-cnt; k < j; k++) {
                            kieru[i][k] = 1;
                            flag = 1;
                        }
                    }
                    cnt = 1;
                    crtColor = field[i][j];
                }
            }
        }
        for (int i = 1; i <= W; i++) {
            char crtColor = field[1][i];
            int cnt = 0;
            for (int j = 1; j <= H+1; j++) {
                if (crtColor == field[j][i] && crtColor != '.') {
                    cnt++;
                } else {
                    if (N <= cnt) {
                        for (int k = j - cnt; k < j; k++) {
                            kieru[k][i] = 1;
                            flag = 1;
                        }
                    }
                    cnt = 1;
                    crtColor = field[j][i];
                }
            }
        }

        HELL:
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                if (field[i][j] == '.') {
                    kieru[i][j] = 1;
                }
            }
        }

        for (int j = 1; j <= W; j++) {
            int startY = H;
            for (int i = H; i >= 1; i--) {
                if (kieru[i][j] == 1) {
                    field[i][j] = '.';
                } else {
                    field[startY][j] = field[i][j];
                    if (i != startY) field[i][j] = '.';
                    startY--;
                }
            }
        }
    }
    int ret = 1;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (field[i][j] != '.' && field[i][j] != '#') {
                ret = 0;
            }
        }
    }
    return ret;
}

int main(void) {
    cin >> H >> W >> N;

    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> Field[i][j];
        }
    }

    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (j+1 <= W) {
                swap(Field[i][j], Field[i][j+1]);
                if (solve()) {
                    cout << "YES" << endl;
                    return 0;
                }
                swap(Field[i][j], Field[i][j+1]);
            }
        }
    }
    cout << "NO" << endl;
}




Measured memory_bytes: 3120