#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()
#define fcout cout << setprecision(10)

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename T>
void debug(vector<T> &vec) {
    for (auto x : vec) {
        cout << x << " ";
    }
    cout << endl;
    return;
}

template <typename T>
int getFormer(const vector<T> &vec, T x) {
    return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}

template <typename T>
int getLatter(const vector<T> &vec, T x) {
    return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

vector<string> table, _table;
int h, w, n;

int fall() {
    int cnt = 0;
    for (int i = h - 1; i > 0; i--) {
        for (int j = w - 1; j >= 0; j--) {
            if (table[i][j] == '.' && table[i - 1][j] != '.') {
                swap(table[i][j], table[i - 1][j]);
                cnt += 1;
            }
        }
    }

    return cnt;
}

void del() {
    vector<vector<bool>> delFlag(h, vector<bool>(w, false));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char self = table[i][j];
            int cnt = 0, x = j, y = i;
            for (int x = j; x < w; x++) {
                if (self == table[i][x]) {
                    cnt += 1;
                } else {
                    break;
                }
            }

            if (cnt >= n) {
                for (int x = j; x < w; x++) {
                    if (self == table[i][x]) {
                        delFlag[i][x] = true;
                    } else {
                        break;
                    }
                }
            }

            cnt = 0;
            for (int y = i; y < h; y++) {
                if (self == table[y][j]) {
                    cnt += 1;
                } else {
                    break;
                }
            }

            if (cnt >= n) {
                for (int y = i; y < h; y++) {
                    if (self == table[y][j]) {
                        delFlag[y][j] = true;
                    } else {
                        break;
                    }
                }
            }
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (delFlag[i][j]) table[i][j] = '.';
        }
    }
}

bool winCheck() {
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (table[i][j] == '.') continue;
            return false;
        }
    }
    return true;
}


bool solve() {
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w - 1; j++) {
            table = _table;
            swap(table[i][j], table[i][j + 1]);
            int cnt = 1;
            while (true) {
                while (cnt) {
                    cnt = fall();
                }
                del();
                cnt = fall();
                if (cnt == 0) {
                    break;
                }
            }

            if(winCheck()) {
                return true;
            }
        }
    }

    return false;
}

int main() {
    cin >> h >> w >> n;
    _table = vector<string>(h);
    REP(i, h) cin >> _table[i];
    cout << (solve() ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 3228