#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i];
    if(i == SZ(s)-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

vector<int> dy = {1, -1, 0, 0};
vector<int> dx = {0, 0, 1, -1};

struct Game {
  vector<vector<char>> board;
  int n, h, w;
  Game(vector<vector<char>> v, int n, int h, int w) {
    board = v;
    this->n = n;
    this->h = h;
    this->w = w;
/*     REP(i, h) {
      printv(board[i]);
    }
    cout << endl; */
  }

  void fall() {
    REP(aaa, h){
      RREP(i, h-2) {
        REP(j, w) {
          if(board[i][j] != '.' && board[i+1][j] == '.') {
            board[i+1][j] = board[i][j];
            board[i][j] = '.';
          }
        }
      }
    }
  }

  bool del() {
    bool upd = false;
    vector<vector<bool>> d(h, vector<bool>(w, false));
    REP(i, h) {
      REP(j, w) {
        char now = board[i][j];
        if(now == '.') continue;
        REP(k, 4) {
          int x = dx[k], y = dy[k];
          vector<P> selpos;
          P pos = make_pair(i, j);
          while(0 <= pos.fi && pos.fi < h && 0 <= pos.se && pos.se <= w &&
                board[pos.fi][pos.se] == now) {
            selpos.push_back(pos);
            pos.fi += x;
            pos.se += y;
          }
          if((int)selpos.size() >= n) {
            REP(l, SZ(selpos)) {
              d[selpos[l].fi][selpos[l].se] = true;
            }
          }
        }
      }
    }

    REP(i, h) {
      REP(j, w) {
        if(d[i][j]) {
          upd = true;
          board[i][j] = '.';
        }
      }
    }

    return upd;
  }

  bool empty(){
    REP(i, h) {
      REP(j, w) {
        if('A' <= board[i][j] && board[i][j] <= 'Z') return false;
      }
    }
    return true;
  }

  bool win() {
    this->fall();
    while(this->del()) {
/*       REP(i, h) {
        printv(board[i]);
      }
      cout << endl; */
      this->fall();
    }
    return this->empty();
  }
};

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  int h, w, n; cin >> h >> w >> n;
  vector<vector<char>> v(h, vector<char>(w));
  REP(i, h) {
    REP(j, w) {
      cin >> v[i][j];
    }
  }

  REP(i, h) {
    REP(j, w) {
      REP(k, 2) {
        int x = i+dx[k], y = j+dy[k];
        if(0 <= x && x < h && 0 <= y && y < w) {
          swap(v[i][j], v[x][y]);
          if(Game(v, n, h, w).win()) {
            cout << "YES" << endl;
            return 0;
          }
          swap(v[i][j], v[x][y]);
        }
      }
    }
  }

  cout << "NO" << endl;
}



Measured memory_bytes: 3148