#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int h;
int w;
int n;

void show(vector<string> &g)
{
    rep(i, h)
    {
        rep(j, w) cerr << g[i][j] << " ";
        cerr << endl;
    }
    cerr << "------------------------------" << endl;
}

bool clear(vector<string> &g)
{
    bool ret = false;
    auto old = g;
    rep(i, h)
    {
        int count = 1;
        char target = '@';
        bool breakf = false;
        rep(j, w)
        {
            if (old[i][j] == target && target != '.')
            {
                count++;
            }
            else
            {
                target = old[i][j];
                count = 1;
                breakf = false;
            }
            if (count == n)
            {
                ret = true;
                rep(k, j - count + 1, j + 1)
                {
                    g[i][k] = '.';
                }
                breakf = true;
            }
            if (breakf == true)
            {
                g[i][j] = '.';
            }
        }
    }
    rep(j, w)
    {
        int count = 1;
        char target = '@';
        bool breakf = false;
        rep(i, h)
        {
            if (old[i][j] == target && target != '.')
            {
                count++;
            }
            else
            {
                target = old[i][j];
                count = 1;
                breakf = false;
            }
            if (count == n)
            {
                ret = true;
                rep(k, i - count + 1, i + 1)
                {
                    g[k][j] = '.';
                }
                breakf = true;
            }
            if (breakf == true)
            {
                g[i][j] = '.';
            }
        }
    }
    return ret;
}

bool update(vector<string> &g)
{

    bool flg = true;
    bool ret = false;
    while (flg)
    {
        flg = false;
        auto old = g;
        rep(i, h - 1) rep(j, w)
        {
            if (old[i][j] != '.' && old[i + 1][j] == '.')
            {
                g[i + 1][j] = g[i][j];
                g[i][j] = '.';
                flg = true;
                ret = true;
            }
        }
    }
    //show(g);

    while (clear(g))
    {
        ret = true;
    //    show(g);
    }
    return ret;
}

bool gameclear(vector<string> &g)
{
    rep(i, h) rep(j, w)
    {
        if (g[i][j] != '.')
            return false;
    }
    return true;
}

int main()
{
    cin >> h >> w >> n;

    vector<string> g;
    rep(i, h)
    {
        string s;
        cin >> s;
        g.push_back(s);
    }
    rep(i, h) rep(j, w - 1)
    {
        // cerr << "NEW : " << i << "," << j << endl;
        auto back = g;
        char tmp = g[i][j];
        g[i][j] = g[i][j + 1];
        g[i][j + 1] = tmp;
        while (update(g))
        {
            // cerr << "update" << endl;
        }
        if (gameclear(g))
        {
            cout << "YES" << endl;
            return 0;
        }
        g = back;
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3232