# 2 "2232.cpp"
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>


namespace solution {
   using namespace std;

   typedef istringstream ISS;
   typedef ostringstream OSS;
   typedef vector<string> VS;
   typedef long long LL;
   typedef int INT;
   typedef vector<INT> VI;
   typedef vector<VI> VVI;
   typedef pair<INT, INT> II;

   const int SIZE = 31;
   const char EMPTY = '.';
   int H, W, N;
   string S[SIZE];
   string T[SIZE];
   string B[SIZE];

   class Solution {
   private:
      void init() {
      }

      bool input() {
         if ( ! ( cin >> H >> W >> N ) ) return false;
         for ( int i = 0; i < H; ++ i ) {
            cin >> S[i];
         }
         return true;
      }


      void dropdown() {
         for ( int i = H-1; i >= 0; -- i ) {
            for ( int j = 0; j < W; ++ j ) {
               for ( int k = i; k + 1 < H; ++ k ) {
                  if ( k+1 < H && T[k][j] != EMPTY && T[k+1][j] == EMPTY ) {
                     T[k+1][j] = T[k][j];
                     T[k][j] = EMPTY;
                  } else {
                     break;
                  }
               }
            }
         }
      }

      bool destroy() {
         for ( int i = 0; i < H; ++ i ) {
            B[i] = T[i];
         }
         bool D[H][W];
         for ( int i = 0; i < H; ++ i ) {
            for ( int j = 0; j < W; ++ j ) {
               D[i][j] = false;
            }
         }
         for ( int i = 0; i < H; ++ i ) {
            for ( int j = 0; j < W; ++ j ) {
               if ( T[i][j] != EMPTY ) {
                  const int dr[2] = { 0, 1 };
                  const int dc[2] = { 1, 0 };
                  for ( int di = 0; di < 2; ++ di ) {
                     int x = 0;
                     for ( int k = 0; i+k*dr[di] < H && j+k*dc[di] < W; ++ k ) {
                        if ( T[i][j] == T[i+k*dr[di]][j+k*dc[di]] ) {
                           x ++;
                        } else {
                           break;
                        }
                     }
                     if ( x >= N ) {
                        for ( int k = 0; k < x; ++ k ) {
                           D[i+k*dr[di]][j+k*dc[di]] = true;
                        }
                     }
                  }
               }
            }
         }
         for ( int i = 0; i < H; ++ i ) {
            for ( int j = 0; j < W; ++ j ) {
               if ( D[i][j] ) T[i][j] = EMPTY;
            }
         }
         for ( int i = 0; i < H; ++ i ) {
            if ( B[i] != T[i] ) return true;
         }
         return false;
      }

      void print_blocks() {
         for ( int i = 0; i < H; ++ i ) {
            for ( int j = 0; j < W; ++ j ) {
               cout << T[i][j];
            }
            cout << endl;
         }
         cout << endl;
      }

      bool check() {
         for ( int i = 0; i < W; ++ i ) {
            if ( T[H-1][i] != EMPTY ) return false;
         }
         return true;
      }

      bool simulate() {
         for ( int i = 0; i < H; ++ i ) {
            T[i] = S[i];
         }
         do {
            dropdown();
         } while ( destroy() );
         return check();
      }

      bool solve() {
         if ( simulate() ) return true;
         for ( int i1 = 0; i1 < H; ++ i1 ) {
            for ( int j1 = 0; j1 < W; ++ j1 ) {
               for ( int j2 = 0; j2 < W; ++ j2 ) {
                  if ( j1 == j2 ) continue;
                  if ( abs( j1 - j2 ) != 1 ) continue;
                  if ( S[i1][j1] == S[i1][j2] ) continue;
                  swap( S[i1][j1], S[i1][j2] );
                  if ( simulate() ) return true;
                  swap( S[i1][j1], S[i1][j2] );
               }
            }
         }
         return false;
      }

      void output( bool result ) {
         cout << ( result ? "YES" : "NO" ) << endl;
      }

   public:
      int run() {
         while ( init(), input() ) {
            output(solve());
         }
         return 0;
      }
   };
}

int main() {
   using namespace solution;
   Solution s;
   return s.run();
}

Measured memory_bytes: 1212