#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

string ss[100];
string sss[100];
bool bo[100][100];
int n;

bool vanish(int h, int w) {
    for (int i = 0; i < w; i++) {
        int num = h - 1;
        for (int j = h - 1; j >= 0; j--) {
            if (ss[j][i] != '.') {
                ss[num][i] = ss[j][i];
                if (num != j) {
                    ss[j][i] = '.';
                }
                num--;
            }
        }
    }
    for (int i = 0; i < h; i++) {
        sss[i] = ss[i];
    }
    for (int p = 0; p < (900 + n - 1) / n; p++) {
        for (int i = 0; i < h; i++) {
            fill(bo[i], bo[i] + w, true);
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (ss[i][j] == '.') {
                    bo[i][j] = false;
                    continue;
                }
                char c = ss[i][j];
                int same[4];
                for (int k = 0; k < 4; k++) {
                    int l = 1;
                    int x = i + l * dx[k];
                    int y = j + l * dy[k];
                    while (x >= 0 && x < h && y >= 0 && y < w) {
                        if (ss[x][y] != c) {
                            break;
                        }
                        l++;
                        x = i + l * dx[k];
                        y = j + l * dy[k];
                    }
                    same[k] = l - 1;
                }
                if (same[0] + same[2] >= n - 1 || same[1] + same[3] >= n - 1) {
                    bo[i][j] = false;
                    sss[i][j] = '.';
                }
            }
        }
        for (int i = 0; i < w; i++) {
            int num = h - 1;
            for (int j = h - 1; j >= 0; j--) {
                if (bo[j][i]) {
                    sss[num][i] = sss[j][i];
                    if (num != j) {
                        sss[j][i] = '.';
                    }
                    num--;
                }
            }
        }
        bool b = true;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (sss[i][j] != '.') {
                    b = false;
                }
            }
        }
        if (b) {
            return true;
        }
        bool bb = true;
        for (int i = 0; i < h; i++) {
            if (ss[i] != sss[i]) {
                bb = false;
            }
        }
        if (bb) {
            return false;
        }
        for (int i = 0; i < h; i++) {
            ss[i] = sss[i];
        }
    }
    // for (int i = 0; i < h; i++) {
    //     for (int j = 0; j < w; j++) {
    //         cout << ss[i][j];
    //     }
    //     cout << endl;
    // }
    // cout << "aaa" << endl;
    return false;
}

int main() {
    int h, w;
    cin >> h >> w >> n;
    string s[h];
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    bool ok = false;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w - 1; j++) {
            for (int k = 0; k < h; k++) {
                ss[k] = s[k];
            }
            swap(ss[i][j], ss[i][j + 1]);
            bool b = false;
            if (ss[i][j] != ss[i][j + 1]) {
                b = vanish(h, w);
            }
            if (b) {
                ok = true;
                break;
            }
        }
        if (ok) {
            break;
        }
    }
    if (ok) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}



Measured memory_bytes: 3240