Language: C++

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

using namespace std;
typedef vector<int> veci;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define foreach(i, n) for (typeof(n) i = 0; i < (n); ++i)
#define foreach_eq(i, n) for (typeof(n) i = 0; i <= (n); ++i)
#define foreach_from(i, m, n) for (typeof(n) i = m; i < (n); ++i)
#define foreach_eq_from(i, m, n) for (typeof(n) i = m; i <= (n); ++i)

int dirctions[4][2] = {{0,-1}, {0,1}, {-1,0}, {1,0}};

#define MAX_H 100
#define MAX_W 100

int H, W;
char data[MAX_H][MAX_W];
stack<pii> stk;

int main() {
    cin >> H >> W;
    foreach (i, H) foreach (j, W) cin >> data[i][j];

    int cnt = 0;
    foreach (i, H) {
        foreach (j, W) {
            char self = data[i][j];
            if (not self) continue;
            ++ cnt;
            stk.push(pii(i,j));
            while (not stk.empty()) {
                pii pos = stk.top();
                stk.pop();
                foreach (d, 4) {
                    pii nxt = pii(pos.first + dirctions[d][0], pos.second + dirctions[d][1]);
                    if (nxt.first < 0 || H <= nxt.first || nxt.second < 0 || W <= nxt.second) continue;
                    if (data[nxt.first][nxt.second] != self) continue;
                    data[nxt.first][nxt.second] = 0;
                    stk.push(nxt);
                }
            }
        }
    }

    cout << cnt << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:41:42: error: reference to 'data' is ambiguous
   41 |     foreach (i, H) foreach (j, W) cin >> data[i][j];
      |                                          ^~~~
In file included from /usr/include/c++/14/deque:68,
                 from a.cc:4:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:36:6: note:                 'char data [100][100]'
   36 | char data[MAX_H][MAX_W];
      |      ^~~~
a.cc:46:25: error: reference to 'data' is ambiguous
   46 |             char self = data[i][j];
      |                         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:36:6: note:                 'char data [100][100]'
   36 | char data[MAX_H][MAX_W];
      |      ^~~~
a.cc:56:25: error: reference to 'data' is ambiguous
   56 |                     if (data[nxt.first][nxt.second] != self) continue;
      |                         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:36:6: note:                 'char data [100][100]'
   36 | char data[MAX_H][MAX_W];
      |      ^~~~
a.cc:57:21: error: reference to 'data' is ambiguous
   57 |                     data[nxt.first][nxt.second] = 0;
      |                     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:36:6: note:                 'char data [100][100]'
   36 | char data[MAX_H][MAX_W];
      |      ^~~~