Language: C++

2#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define whole(xs) xs.begin(), xs.end()

ostream& operator<<(ostream& os, const vector<string>& v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << endl;
    }
    return os;
}

int H, W, N;
#define MH 30
#define MW 30
vector<string> F;

const int dy[] = {0, 1, 0, -1},
          dx[] = {1, 0, -1, 0};
void Drop(vector<string>& F1);
void DeleteMarked(vector<string>& F1, bool Mark[MH][MW]) {
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (Mark[y][x]) {
                F1[y][x] = '.';
            }
        }
    }
    Drop(F1);
}

void Drop(vector<string>& F1) {
    bool Changed = true;
    while (Changed) {
        Changed = false;
        for (int y = 0; y < H; y++) {
            for (int x = 0; x < W; x++) {
                if (!isalpha(F1[y][x])) continue;
                if (y + 1 < H && F1[y + 1][x] == '.') {
                    Changed = true;
                    swap(F1[y][x], F1[y + 1][x]);
                }
            }
        }
    }
}

bool Finished(const vector<string>& F1);
bool Check(vector<string> F1) {
    if (Finished(F1)) return true;
    Drop(F1);
    bool Mark[MH][MW];
    memset(Mark, 0, sizeof(Mark));
    for (int y = 0; y < H; y++) {
        char prev = F1[y][0];
        int n = 1;
        for (int x = 1; x <= W; x++) {
            if (x < W && F1[y][x] == prev) {
                n++;
            } else {
                if (n >= N) {
                    for (int x1 = x - 1; x1 >= x - n; x1--) {
                        Mark[y][x1] = true;
                    }
                }
                if (x < W) {
                    n = 1;
                    prev = F1[y][x];
                }
            }
        }
    }
    for (int x = 0; x < W; x++) {
        char prev = F1[0][x];
        int n = 1;
        for (int y = 1; y <= H; y++) {
            if (y < H && F1[y][x] == prev) {
                n++;
            } else {
                if (n >= N) {
                    for (int y1 = y - 1; y1 >= y - n; y1--) {
                        Mark[y1][x] = true;
                    }
                }
                if (y < H) {
                    n = 1;
                    prev = F1[y][x];
                }
            }
        }
    }
    vector<string> prevF1 = F1;
    /*
    cerr << "before" << endl << prevF1 << endl;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) 
            cerr << Mark[i][j] << " ";
        cerr << endl;
    }
    cerr << "after" << endl << F1 << endl;
    */
    DeleteMarked(F1, Mark);
    if (F1 == prevF1) return false;
    return Check(F1);
}

bool Finished(const vector<string>& F1) {
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (F1[y][x] != '.') {
                return false;
            }
        }
    }
    return true;
}

bool solve() {
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (!isalpha(F[y][x])) continue;
            for (int d = -1; d <= 1; d += 2) {
                int ny = y,
                    nx = x + d;
                if (ny < 0 || ny >= H) continue;
                if (nx < 0 || nx >= W) continue;
                //if (!isalpha(F[ny][nx])) continue;
                swap(F[y][x], F[ny][nx]);
                if (Check(F)) {
                    return true;
                }
                swap(F[ny][nx], F[y][x]);
            }
        }
    }
    return false;
}

void input() {
    cin >> H >> W >> N;
    F.resize(H);
    for (int i = 0; i < H; i++) {
        cin >> F[i];
    }
}

int main() {
    input(); 
    cout << (solve() ? "YES" : "NO") << endl;
    return 0;
}

Compiler output:
a.cc:1:2: error: stray '#' in program
    1 | 2#include <algorithm>
      |  ^
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 2#include <algorithm>
      | ^
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/stl_function.h:60,
                 from /usr/include/c++/14/functional:49,
                 from a.cc:6:
/usr/include/c++/14/type_traits:666:33: error: 'nullptr_t' is not a member of 'std'
  666 |     struct is_null_pointer<std::nullptr_t>
      |                                 ^~~~~~~~~
/usr/include/c++/14/type_traits:666:42: error: template argument 1 is invalid
  666 |     struct is_null_pointer<std::nullptr_t>
      |                                          ^
/usr/include/c++/14/type_traits:670:48: error: template argument 1 is invalid
  670 |     struct is_null_pointer<const std::nullptr_t>
      |                                                ^
/usr/include/c++/14/type_traits:674:51: error: template argument 1 is invalid
  674 |     struct is_null_pointer<volatile std::nullptr_t>
      |                                                   ^
/usr/include/c++/14/type_traits:678:57: error: template argument 1 is invalid
  678 |     struct is_null_pointer<const volatile std::nullptr_t>
      |                                                         ^
/usr/include/c++/14/type_traits:1429:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
 1429 |     : public integral_constant<std::size_t, alignof(_Tp)>
      |                                     ^~~~~~
In file included from /usr/include/stdio.h:34,
                 from /usr/include/c++/14/cstdio:42,
                 from a.cc:2:
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/type_traits:1429:57: error: template argument 1 is invalid
 1429 |     : public integral_constant<std::size_t, alignof(_Tp)>
      |                                                         ^
/usr/include/c++/14/type_traits:1429:57: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1438:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
 1438 |     : public integral_constant<std::size_t, 0> { };
      |                                     ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/type_traits:1438:46: error: template argument 1 is invalid
 1438 |     : public integral_constant<std::size_t, 0> { };
      |                                              ^
/usr/include/c++/14/type_traits:1438:46: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1440:26: error: 'std::size_t' has not been declared
 1440 |   template<typename _Tp, std::size_t _Size>
      |                          ^~~
/usr/include/c++/14/type_traits:1441:21: error: '_Size' was not declared in this scope
 1441 |     struct rank<_Tp[_Size]>
      |                     ^~~~~
/usr/include/c++/14/type_traits:1441:27: error: template argument 1 is invalid
 1441 |     struct rank<_Tp[_Size]>
      |                           ^
/usr/include/c++/14/type_traits:1442:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
 1442 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                     ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/type_traits:1442:65: error: template argument 1 is invalid
 1442 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                                                 ^
/usr/include/c++/14/type_traits:1442:65: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1446:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
 1446 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                     ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/type_traits:1446:65: error: template argument 1 is invalid
 1446 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                                                 ^
/usr/include/c++/14/type_traits:1446:65: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:2086:26: error: 'std::size_t' has not been declared
 2086 |   template<typename _Tp, std::size_t _Size>
      |                          ^~~
/usr/include/c++/14/type_traits:2087:30: error: '_Size' was not declared in this scope
 2087 |     struct remove_extent<_Tp[_Size]>
      |                              ^~~~~
/usr/include/c++/14/type_traits:2087:36: error: template argument 1 is invalid
 2087 |     struct remove_extent<_Tp[_Size]>
      |                                    ^
/usr/include/c++/14/type_traits:2099:26: error: 'std::size_t' has not been declared
 2099 |   template<typename _Tp, std::size_t _Size>
      |                          ^~~
/usr/include/c++/14/type_traits:2100:35: error: '_Size' was not declared in this scope
 2100 |     struct remove_all_extents<_Tp[_Size]>
      |                                   ^~~~~
/usr/include/c++/14/type_traits:2100:41: error: template argument 1 is invalid
 2100 |     struct remove_all_extents<_Tp[_Size]>
      |                                         ^
/usr/include/c++/14/type_traits:2171:12: error: 'std::size_t' has not been declared
 2171 |   template<std::size_t _Len>
      |            ^~~
/usr/include/c++/14/type_traits:2176:30: error: '_Len' was not declared in this scope
 2176 |         unsigned char __data[_Len];
      |                              ^~~~
/usr/include/c++/14/type_traits:2194:12: error: 'std::size_t' has not been declared
 2194 |   template<std::size_t _Len, std::size_t _Align =
      |            ^~~
/usr/include/c++/14/type_traits:2194:30: error: 'std::size_t' has not been declared
 2194 |   template<std::size_t _Len, std::size_t _Align =
      |                              ^~~
/usr/include/c++/14/type_traits:2195:55: error: '_Len' was not declared in this scope
 2195 |            __alignof__(typename __aligned_storage_msa<_Len>::__type)>
      |                                                       ^~~~
/usr/include/c++/14/type_traits:2195:59: error: template argument 1 is invalid
 2195 |            __alignof__(typename __aligned_storage_msa<_Len>::__type)>
      |                                                           ^
/usr/include/c++/14/type_traits:2202:30: error: '_Len' was not declared in this scope
 2202 |         unsigned char __data[_Len];
      |                              ^~~~
/usr/include/c++/14/type_traits:2203:44: error: '_Align' was not declared in this scope
 2203 |         struct __attribute__((__aligned__((_Align)))) { } __align;
      |                                            ^~~~~~
In file included from /usr/include/c++/14/functional:55:
/usr/include/c++/14/bits/functional_hash.h:273:17: error: 'nullptr_t' was not declared in this scope
  273 |     struct hash<nullptr_t> : public __hash_base<size_t, nullptr_t>
      |                 ^~~~~~~~~
/usr/include/c++/14/bits/functional_hash.h:37:1: note: 'nullptr_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
   36 | #include <bits/hash_bytes.h>
  +++ |+#include <cstddef>
   37 | 
/usr/include/c++/14/bits/functional_hash.h:273:26: error: template argument 1 is invalid
  273 |     struct hash<nullptr_t> : public __hash_base<size_t, nullptr_t>
      |                          ^
/usr/include/c++/14/bits/functional_hash.h:273:57: error: 'nullptr_t' was not declared in this scope
  273 |     struct hash<nullptr_t> : public __hash_base<size_t, nullptr_t>
      |                                                         ^~~~~~~~~
/usr/include/c++/14/bits/functional_hash.h:273:57: note: 'nullptr_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/c++/14/bits/functional_hash.h:273:66: error: template argument 2 is invalid
  273 |     struct hash<nullptr_t> : public __hash_base<size_t, nullptr_t>
      |                                                                  ^
In file included from /usr/include/c++/14/bits/std_function.h:39,
                 from /usr/include/c++/14/functional:59:
/usr/include/c++/14/new:131:26: error: declaration of 'operator new' as non-function
  131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                          ^~~~~~~~
/usr/include/c++/14/new:131:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
  131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                                            ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/include/c++/14/new:132:41: error: attributes after parenthesized initializer ignored [-fpermissive]
  132 |   __attribute__((__externally_visible__));
      |                                         ^
/usr/include/c++/14/new:133:26: error: declaration of 'operator new []' as non-function
  133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                          ^~~~~~~~
/usr/include/c++/14/new:133:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
  133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                                              ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
  214 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
/usr/inc