Language: C++

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0; i < n; i++)
#define int long long
using namespace std;

int h, w;
string s[400];
int xor[400][400];
bool used[400][400];
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};

signed main() {
	int i, j;
	
	cin >> h >> w;
	rep(i, h) cin >> s[i];
	
	rep(i, h) {
		rep(j, w) {
			int v = (s[i][j] == '#');
			xor[i][j] = ((i + j) % 2 != v);
			//cout << xor[i][j];
		}
		//cout << endl;
	}
	
	int ans = 0;
	typedef pair<int, int> P;
	queue<P> que;
	rep(i, h) {
		rep(j, w) {
			int wcnt = 0;
			int bcnt = 0;
			if (used[i][j]) continue;
			
			used[i][j] = true;
			que.push(P(i, j));
			if (s[i][j] == '.') wcnt++; else bcnt++;
			while (!que.empty()) {
				P now = que.front(); que.pop();
				int y = now.first;
				int x = now.second;
				int dir;
				rep(dir, 4) {
					int ny = y + dy[dir];
					int nx = x + dx[dir];
					if (ny < 0 || ny >= h || nx < 0 || nx >= w || used[ny][nx] || xor[ny][nx] != xor[y][x]) continue;
					que.push(P(ny, nx));
					used[ny][nx] = true;
					if (s[ny][nx] == '.') wcnt++; else bcnt++;
				}
			}
			ans += wcnt * bcnt;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc:20:5: error: expected unqualified-id before 'xor' token
   20 | int xor[400][400];
      |     ^~~
a.cc: In function 'int main()':
a.cc:34:25: error: expected primary-expression before 'xor' token
   34 |                         xor[i][j] = ((i + j) % 2 != v);
      |                         ^~~
a.cc: In lambda function:
a.cc:34:31: error: expected '{' before '[' token
   34 |                         xor[i][j] = ((i + j) % 2 != v);
      |                               ^
a.cc: In function 'int main()':
a.cc:34:31: error: no match for 'operator[]' (operand types are 'main()::<lambda()>' and 'long long int')
a.cc:60:103: error: expected primary-expression before 'xor' token
   60 |                                         if (ny < 0 || ny >= h || nx < 0 || nx >= w || used[ny][nx] || xor[ny][nx] != xor[y][x]) continue;
      |                                                                                                       ^~~
a.cc: In lambda function:
a.cc:60:110: error: expected '{' before '[' token
   60 |                                         if (ny < 0 || ny >= h || nx < 0 || nx >= w || used[ny][nx] || xor[ny][nx] != xor[y][x]) continue;
      |                                                                                                              ^
a.cc: In function 'int main()':
a.cc:60:110: error: no match for 'operator[]' (operand types are 'main()::<lambda()>' and 'long long int')
a.cc:60:118: error: expected primary-expression before 'xor' token
   60 |                                         if (ny < 0 || ny >= h || nx < 0 || nx >= w || used[ny][nx] || xor[ny][nx] != xor[y][x]) continue;
      |                                                                                                                      ^~~
a.cc: In lambda function:
a.cc:60:124: error: expected '{' before '[' token
   60 |                                         if (ny < 0 || ny >= h || nx < 0 || nx >= w || used[ny][nx] || xor[ny][nx] != xor[y][x]) continue;
      |                                                                                                                            ^
a.cc: In function 'int main()':
a.cc:60:124: error: no match for 'operator[]' (operand types are 'main()::<lambda()>' and 'long long int')