#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
const int MAX_N = 40;
int H, W, N;
bool OK = false;
bool InField(int, int);
void Drop(vector<vector<char>>&);
void Disappear(vector<vector<char>>&);
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W >> N;
    vector<vector<char>> field(MAX_N, vector<char>(MAX_N));
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++) cin >> field[i][j];
    }
    bool ok = false;
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            int ny = i, nx = j + 1;
            if(!InField(ny, nx)) continue;
            if(field[ny][nx] == field[i][j]) continue;
            vector<vector<char>> tmp(field);
            swap(tmp[ny][nx], tmp[i][j]);
            Drop(tmp);
            if(OK)
            {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}
bool InField(int y, int x)
{
    if(y < 0 || x < 0 || y >= H || x >= W) return false;
    else return true;
}
void Drop(vector<vector<char>> &field)
{
    bool flag = false;
    for(int i = H - 1; i >= 0; i--)
    {
        for(int j = 0; j < W; j++)
        {
            if(field[i][j] == '.') continue;
            flag = true;
            int ny = i + 1;
            while(1)
            {
                if(ny >= H || field[ny][j] != '.')
                {
                    swap(field[ny - 1][j], field[i][j]);
                    break;
                }
                ny++;
            }
        }
    }
    Disappear(field);
    if(!flag)
    {
        OK = true;
        return;
    }
}
void Disappear(vector<vector<char>> &field)
{
    vector<vector<char>> tmp(field);
    bool flag = false;
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            if(field[i][j] == '.') continue;
            char ch = field[i][j];
            for(int k = 0; k < 4; k++)
            {
                int ny = i, nx = j;
                int cnt = 0;
                queue<P> que;
                while(InField(ny, nx))
                {
                    if(field[ny][nx] != ch) break;
                    que.push(P(ny, nx));
                    cnt++;
                    ny += dy[k];
                    nx += dx[k];
                }
                if(cnt >= N)
                {
                    flag = true;
                    while(!que.empty())
                    {
                        P p = que.front();
                        que.pop();
                        if(tmp[p.first][p.second] == '.') break;
                        tmp[p.first][p.second] = '.';
                    }
                }
            }
        }
    }
    field = tmp;
    if(flag == false) return;
    else Drop(field);
}


Measured memory_bytes: 3284