Language: C++

#include<map>
#include<iostream>
#include<iomanip>
#include<algorithm>

#define mp make_pair

using namespace std;

const int Mxn=100005;
const int Mxm=1005;
int n,m,tm,fm;
int sum[Mxm*4][Mxm*4];
struct in{
	int x,y;
	char c;
}a[Mxn];
inline int find(int x,int y,int X,int Y){
	return sum[x][y]-sum[x][Y+1]-sum[X+1][y]+sum[X+1][Y+1];
}
int main(){
	cin>>n>>m;
	tm=m*2;
	fm=tm*2;
	int i,j;
	for(i=1;i<=n;i++) cin>>a[i].x>>a[i].y>>a[i].c;
	for(i=1;i<=n;i++){
		if(a[i].c=='B') sum[a[i].x%tm][a[i].y%tm]++;
		else sum[(a[i].x+m)%tm][a[i].y%tm]++;
	}
	for(i=1;i<=tm;i++) for(j=1;j<=tm;j++){
		sum[i][j+tm]=sum[i][j];
		sum[i+tm][j]=sum[i][j];
		sum[i+tm][j+tm]=sum[i][j];
	}
	for(i=fm-1;i>-1;i--) for(j=fm-1;j>-1;j--) sum[i][j]=sum[i][j]+sum[i+1][j]+sum[i][j+1]-sum[i+1][j+1];
	int ans=0;
	for(i=1;i<=tm;i++) for(j=1;j<=tm;j++) ans=max(ans,find(i,j,i+m-1,j+m-1)+find(i+m,j+m,i+tm-1,j+tm-1));
	cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:9: error: reference to 'tm' is ambiguous
   23 |         tm=m*2;
      |         ^~
In file included from /usr/include/time.h:39,
                 from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:24:12: error: reference to 'tm' is ambiguous
   24 |         fm=tm*2;
      |            ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:28:44: error: reference to 'tm' is ambiguous
   28 |                 if(a[i].c=='B') sum[a[i].x%tm][a[i].y%tm]++;
      |                                            ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:28:55: error: reference to 'tm' is ambiguous
   28 |                 if(a[i].c=='B') sum[a[i].x%tm][a[i].y%tm]++;
      |                                                       ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:29:37: error: reference to 'tm' is ambiguous
   29 |                 else sum[(a[i].x+m)%tm][a[i].y%tm]++;
      |                                     ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:29:48: error: reference to 'tm' is ambiguous
   29 |                 else sum[(a[i].x+m)%tm][a[i].y%tm]++;
      |                                                ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:31:20: error: reference to 'tm' is ambiguous
   31 |         for(i=1;i<=tm;i++) for(j=1;j<=tm;j++){
      |                    ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:31:39: error: reference to 'tm' is ambiguous
   31 |         for(i=1;i<=tm;i++) for(j=1;j<=tm;j++){
      |                                       ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:32:26: error: reference to 'tm' is ambiguous
   32 |                 sum[i][j+tm]=sum[i][j];
      |                          ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:33:23: error: reference to 'tm' is ambiguous
   33 |                 sum[i+tm][j]=sum[i][j];
      |                       ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:34:23: error: reference to 'tm' is ambiguous
   34 |                 sum[i+tm][j+tm]=sum[i][j];
      |                       ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:34:29: error: reference to 'tm' is ambiguous
   34 |                 sum[i+tm][j+tm]=sum[i][j];
      |                             ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:38:20: error: reference to 'tm' is ambiguous
   38 |         for(i=1;i<=tm;i++) for(j=1;j<=tm;j++) ans=max(ans,find(i,j,i+m-1,j+m-1)+find(i+m,j+m,i+tm-1,j+tm-1));
      |                    ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:38:39: error: reference to 'tm' is ambiguous
   38 |         for(i=1;i<=tm;i++) for(j=1;j<=tm;j++) ans=max(ans,find(i,j,i+m-1,j+m-1)+find(i+m,j+m,i+tm-1,j+tm-1));
      |                                       ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:38:96: error: reference to 'tm' is ambiguous
   38 |         for(i=1;i<=tm;i++) for(j=1;j<=tm;j++) ans=max(ans,find(i,j,i+m-1,j+m-1)+find(i+m,j+m,i+tm-1,j+tm-1));
      |                                                                                                ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~
a.cc:38:103: error: reference to 'tm' is ambiguous
   38 |         for(i=1;i<=tm;i++) for(j=1;j<=tm;j++) ans=max(ans,find(i,j,i+m-1,j+m-1)+find(i+m,j+m,i+tm-1,j+tm-1));
      |                                                                                                       ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:12:9: note:                 'int tm'
   12 | int n,m,tm,fm;
      |         ^~