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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int h, w, n;
char mp[30][30], mp2[30][30];
bool marked[30][30];

void dup() { rep(i, 0, w) rep(j, 0, h) mp2[i][j] = mp[i][j]; }

void printboard(char m[30][30]) {
    for (int i = h - 1; i >= 0; i--) {
        for (int j = 0; j < w; j++)
            cout << m[j][i];
        cout << endl;
    }
}

void gravi() {
    rep(i, 0, w) {
        int p = 0;
        rep(j, 0, h) {
            if (mp2[i][j] != '.') {
                mp2[i][p] = mp2[i][j];
                if (j > p) {
                    mp2[i][j] = '.';
                }
                p++;
            }
        }
    }
}

// sim on mp2
bool sim() {
    rep(i, 0, w) rep(j, 0, h) marked[i][j] = 0;
    gravi();
    rep(i, 0, w) {
        int prev = 0;
        rep(j, 1, h) {
            if (mp2[i][j] != mp2[i][prev]) {
                if (j - prev >= n && mp2[i][prev] != '.') {
                    // cerr << "Mark " << i << " ; " << prev << " - " << j-1 << endl;
                    rep(k, prev, j) marked[i][k] = 1;
                }
                prev = j;
            }
        }
        if (h - prev >= n && mp2[i][prev] != '.') {
            // cerr << "Mark " << i << " ; " << prev << " - " << h-1 << endl;
            rep(k, prev, h) marked[i][k] = 1;
        }
    }
    rep(i, 0, h) {
        int prev = 0;
        rep(j, 1, w) {
            if (mp2[j][i] != mp2[prev][i]) {
                if (j - prev >= n && mp2[prev][i] != '.') {
                    // cerr << "Mark " << prev << " - " << j-1 << " ; " << i << endl;
                    rep(k, prev, j) marked[k][i] = 1;
                }
                prev = j;
            }
        }
        if (w - prev >= n && mp2[prev][i] != '.') {
            // cerr << "Mark " << prev << " - " << h-1 << " ; " << i << endl;
            rep(k, prev, w) marked[k][i] = 1;
        }
    }
    bool diff = false;
    rep(i, 0, w) rep(j, 0, h) if (marked[i][j]) {
        // cout << "Mark " << i << " " << j << endl;
        mp2[i][j] = '.', diff = true;
    }

    // gravitation
    gravi();

    return diff;
}

bool good() {
    rep(i, 0, w) if (mp2[i][0] != '.') return false;
    return true;
}

int main() {
    cin >> h >> w >> n;
    // w -> h
    for (int i = h - 1; i >= 0; i--)
        for (int j = 0; j < w; j++)
            cin >> mp[j][i];
    rep(i, 0, w) rep(j, 0, h) {
        if (i + 1 < w && mp[i][j] != mp[i + 1][j]) {
            dup();
            swap(mp2[i][j], mp2[i + 1][j]);
            while (sim())
                ;
            if (good()) {
                cout << "YES" << endl;
                return 0;
            }
        }
        // if (j + 1 < h && mp[i][j] != mp[i][j + 1]) {
        //     dup();
        //     swap(mp2[i][j], mp2[i][j + 1]);
        //     while (sim())
        //         ;
        //     if (good()) {
        //         cout << "YES" << endl;
        //         return 0;
        //     }
        // }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 3112