Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<int um> class UF {
	public:
	vector<int> par,rank;
	UF() {rank=vector<int>(um,0); for(int i=0;i<um;i++) par.push_back(i);}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<500000> uf;

int H,W;
string S[404];
int C[404*404][2];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(y,H) cin>>S[y];
	}
	
	
	FOR(y,H) FOR(x,W) {
		if(y && S[y][x]!=S[y-1][x]) uf(y*W+x,(y-1)*W+x);
		if(x && S[y][x]!=S[y][x-1]) uf(y*W+x,y*W+x-1);
	}
	
	FOR(y,H) FOR(x,W) C[uf[y*W+x]][(y+x)%2]++;
	
	
	ll ret=0;
	FOR(i,H*W) ret+=1LL*C[i][0]*C[i][1];
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Compiler output:
a.cc:7:19: error: expected unqualified-id before 'for'
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                   ^~~
a.cc:40:9: note: in expansion of macro 'FOR'
   40 |         FOR(y,H) FOR(x,W) {
      |         ^~~
a.cc:40:13: error: 'y' does not name a type
   40 |         FOR(y,H) FOR(x,W) {
      |             ^
a.cc:7:27: note: in definition of macro 'FOR'
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                           ^
a.cc:40:13: error: 'y' does not name a type
   40 |         FOR(y,H) FOR(x,W) {
      |             ^
a.cc:7:34: note: in definition of macro 'FOR'
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                                  ^
a.cc:40:22: error: 'x' does not name a type
   40 |         FOR(y,H) FOR(x,W) {
      |                      ^
a.cc:7:27: note: in definition of macro 'FOR'
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                           ^
a.cc:40:22: error: 'x' does not name a type
   40 |         FOR(y,H) FOR(x,W) {
      |                      ^
a.cc:7:34: note: in definition of macro 'FOR'
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                                  ^
a.cc:7:19: error: expected unqualified-id before 'for'
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                   ^~~
a.cc:45:9: note: in expansion of macro 'FOR'
   45 |         FOR(y,H) FOR(x,W) C[uf[y*W+x]][(y+x)%2]++;
      |         ^~~
a.cc:45:13: error: 'y' does not name a type
   45 |         FOR(y,H) FOR(x,W) C[uf[y*W+x]][(y+x)%2]++;
      |             ^
a.cc:7:27: note: in definition of macro 'FOR'
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                           ^
a.cc:45:13: error: 'y' does not name a type
   45 |         FOR(y,H) FOR(x,W) C[uf[y*W+x]][(y+x)%2]++;
      |             ^
a.cc:7:34: note: in definition of macro 'FOR'
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                                  ^
a.cc:45:22: error: 'x' does not name a type
   45 |         FOR(y,H) FOR(x,W) C[uf[y*W+x]][(y+x)%2]++;
      |                      ^
a.cc:7:27: note: in definition of macro 'FOR'
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                           ^
a.cc:45:22: error: 'x' does not name a type
   45 |         FOR(y,H) FOR(x,W) C[uf[y*W+x]][(y+x)%2]++;
      |                      ^
a.cc:7:34: note: in definition of macro 'FOR'
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                                  ^
a.cc:7:19: error: expected unqualified-id before 'for'
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                   ^~~
a.cc:49:9: note: in expansion of macro 'FOR'
   49 |         FOR(i,H*W) ret+=1LL*C[i][0]*C[i][1];
      |         ^~~
a.cc:49:13: error: 'i' does not name a type
   49 |         FOR(i,H*W) ret+=1LL*C[i][0]*C[i][1];
      |             ^
a.cc:7:27: note: in definition of macro 'FOR'
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                           ^
a.cc:49:13: error: 'i' does not name a type
   49 |         FOR(i,H*W) ret+=1LL*C[i][0]*C[i][1];
      |             ^
a.cc:7:34: note: in definition of macro 'FOR'
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                                  ^
a.cc:50:9: error: 'cout' does not name a type
   50 |         cout<<ret<<endl;
      |         ^~~~
a.cc:53:1: error: expected declaration before '}' token
   53 | }
      | ^