#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
#define INF 1e9
using namespace std;
template<typename T> void cmin(T &a, T b) { a = min(a, b); }
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
int dy[2] = {0, 1};
int dx[2] = {1, 0};
char mp[50][50], pm[50][50], d[50][50];
int h, w, n;

void del() {
  rep(i, 50) rep(j, 50) d[i][j] = '$';

  //落とす作業
  for (int j = 0; j < w; j++) {
    for (int i = h - 1; i >= 1; i--) {
      int cnt = 0;
      if (pm[i][j] == '.') {
        while (pm[i - cnt][j] == '.' && i - cnt >= 0) cnt++;
        if (i - cnt >= 0) swap(pm[i][j], pm[i - cnt][j]);
      }
    }
  }
  //消す部分を見つける
  rep(i, h) rep(j, w) {
    if (pm[i][j] == '.') continue;
    int posx = j, posy = i;
    int cnt = 0;
    //横方向
    while (posx < w && pm[i][j] == pm[i][posx]) cnt++, posx++;
    if (cnt >= n)
      for (int jj = j; jj < posx; jj++) d[i][jj] = '.';

    cnt = 0;
    //たて方向
    while (posy < h && pm[i][j] == pm[posy][j]) cnt++, posy++;
    if (cnt >= n)
      for (int ii = i; ii < posy; ii++) d[ii][j] = '.';
  }
  //消す
  bool cflag = false;
  rep(i, h) rep(j, w) if (d[i][j] == '.') pm[i][j] = '.', cflag = true;

  //  debug
  // cout << "debug" << endl;
  // rep(i, h) {
  //   rep(j, w) cout << d[i][j];
  //   cout << ' ';
  //   rep(j, w) cout << pm[i][j];
  //   cout << endl;
  // }
  // cout << endl;

  if (cflag)
    del();
  else
    return;
}

bool check() {
  rep(i, h) rep(j, w) if (pm[i][j] != '.') return false;
  return true;
}

signed main() {
  cin >> h >> w >> n;
  rep(i, h) rep(j, w) cin >> mp[i][j];
  bool flag = false;

  rep(i, h) rep(j, w - 1) {
    rep(k, h) rep(l, w) pm[k][l] = mp[k][l];

    swap(pm[i][j], pm[i][j + 1]);

    del();

    // cout << "final state" << ' ' << "x=" << j << ' ' << "x+1=" << j + 1 << endl;
    // rep(i, h) {
    //   rep(j, w) cout << pm[i][j];
    //   cout << ' ';
    //   rep(j, w) cout << mp[i][j];
    //   cout << endl;
    // }
    // cout << endl;

    if (check()) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

