Language: C++

#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;

int m,n;
vector<P> data[30];
vector<int> xind;
vector<int> yind;
int field[190][190];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int pickl[4];
int picklx[4];
int pickly[4];

int main(void){
	scanf("%d %d",&n,&m);
	memset(field,0,sizeof(field));
	for(int i=0;i<n;i++){
		string str;
		cin >> str;
		for(int j=0;j<m;j++){
			if(str[j]>='A' && str[j]<='Z'){
				data[str[j]-'A'+1].push_back(P(j,i));
				if(j-1>=0)xind.push_back(j-1);
				xind.push_back(j);
				if(j+1<m)xind.push_back(j+1);
				if(i-1>=0)yind.push_back(i-1);
				yind.push_back(i);
				if(i+1<n)yind.push_back(i+1);
			}
		}
	}
	sort(xind.begin(),xind.end());
	xind.erase(unique(xind.begin(),xind.end()),xind.end());
	sort(yind.begin(),yind.end());
	yind.erase(unique(yind.begin(),yind.end()),yind.end());
	for(int i=1;i<=26;i++){
		for(int j=0;j<data[i].size();j++){
			data[i][j].first=lower_bound(xind.begin(),xind.end(),data[i][j].first)-xind.begin();
			data[i][j].second=lower_bound(yind.begin(),yind.end(),data[i][j].second)-yind.begin();
			field[data[i][j].first][data[i][j].second]=i;
		}
	}
	bool flag=true;
	int score2=0;
	while(flag){
		flag=false;
		for(int i=0;i<yind.size();i++){
			for(int j=0;j<xind.size();j++){
				if(field[j][i]==0){
					memset(pickl,0,sizeof(pickl));
					for(int k=0;k<4;k++){
						int xx=j,yy=i;
						int xi=xind.size(),yi=yind.size();
						while(xx>=0 && xx<xi && yy>=0 && yy<yi){
							if(field[xx][yy]!=0)break;
							xx+=dx[k];
							yy+=dy[k];
							cnt++;
						}
						if(field[xx][yy]!=0){
							pickl[k]=field[xx][yy];
							picklx[k]=xx;
							pickly[k]=yy;
						}
					}
					for(int k=0;k<4;k++){
						for(int l=k+1;l<4;l++){
							if(pickl[k]==pickl[l] && pickl[k]!=0){
								score2+=2;
								field[picklx[k]][pickly[k]]=0;
								field[picklx[l]][pickly[l]]=0;
								flag=true;
							}
						}
					}
				}
			}
		}
	}
	printf("%d\n",score2);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:33: error: reference to 'data' is ambiguous
   30 |                                 data[str[j]-'A'+1].push_back(P(j,i));
      |                                 ^~~~
In file included from /usr/include/c++/14/string:53,
                 from a.cc:3:
/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:12:11: note:                 'std::vector<std::pair<int, int> > data [30]'
   12 | vector<P> data[30];
      |           ^~~~
a.cc:45:31: error: reference to 'data' is ambiguous
   45 |                 for(int j=0;j<data[i].size();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:12:11: note:                 'std::vector<std::pair<int, int> > data [30]'
   12 | vector<P> data[30];
      |           ^~~~
a.cc:46:25: error: reference to 'data' is ambiguous
   46 |                         data[i][j].first=lower_bound(xind.begin(),xind.end(),data[i][j].first)-xind.begin();
      |                         ^~~~
/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:12:11: note:                 'std::vector<std::pair<int, int> > data [30]'
   12 | vector<P> data[30];
      |           ^~~~
a.cc:46:78: error: reference to 'data' is ambiguous
   46 |                         data[i][j].first=lower_bound(xind.begin(),xind.end(),data[i][j].first)-xind.begin();
      |                                                                              ^~~~
/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:12:11: note:                 'std::vector<std::pair<int, int> > data [30]'
   12 | vector<P> data[30];
      |           ^~~~
a.cc:47:25: error: reference to 'data' is ambiguous
   47 |                         data[i][j].second=lower_bound(yind.begin(),yind.end(),data[i][j].second)-yind.begin();
      |                         ^~~~
/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:12:11: note:                 'std::vector<std::pair<int, int> > data [30]'
   12 | vector<P> data[30];
      |           ^~~~
a.cc:47:79: error: reference to 'data' is ambiguous
   47 |                         data[i][j].second=lower_bound(yind.begin(),yind.end(),data[i][j].second)-yind.begin();
      |                                                                               ^~~~
/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:12:11: note:                 'std::vector<std::pair<int, int> > data [30]'
   12 | vector<P> data[30];
      |           ^~~~
a.cc:48:31: error: reference to 'data' is ambiguous
   48 |                         field[data[i][j].first][data[i][j].second]=i;
      |                               ^~~~
/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:12:11: note:                 'std::vector<std::pair<int, int> > data [30]'
   12 | vector<P> data[30];
      |           ^~~~
a.cc:48:49: error: reference to 'data' is ambiguous
   48 |                         field[data[i][j].first][data[i][j].second]=i;
      |                                                 ^~~~
/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:12:11: note:                 'std::vector<std::pair<int, int> > data [30]'
   12 | vector<P> data[30];
      |