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> xindex;
vector<int> yindex;
int field[250][250];
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(fie,0,sizeof(fie));
	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)xindex.push_back(j-1);
				xindex.push_back(j);
				if(j+1<m)xindex.push_back(j+1);
				if(i-1>=0)yindex.push_back(i-1);
				yindex.push_back(i);
				if(i+1<n)yindex.push_back(i+1);
			}
		}
	}
	sort(xindex.begin(),xindex.end());
	xindex.erase(unique(xindex.begin(),xindex.end()),xindex.end());
	sort(yindex.begin(),yindex.end());
	yindex.erase(unique(yindex.begin(),yindex.end()),yindex.end());
	for(int i=1;i<=26;i++){
		for(int j=0;j<data[i].size();j++){
			data[i][j].first=lower_bound(xindex.begin(),xindex.end(),data[i][j].first)-xindex.begin();
			data[i][j].second=lower_bound(yindex.begin(),yindex.end(),data[i][j].second)-yindex.begin();
			field[data[i][j].first][data[i][j].second]=i;
		}
	}
	bool flag=true;
	int score=0;
	while(flag){
		flag=false;
		for(int i=0;i<yindex.size();i++){
			for(int j=0;j<xindex.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=xindex.size(),yi=yindex.size();
						while(xx>=0 && xx<xi && yy>=0 && yy<yi){
							if(field[xx][yy]!=0)break;
							xx+=dx[k];
							yy+=dy[k];
						}
						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){
								score+=2;
								field[picklx[k]][pickly[k]]=0;
								field[picklx[l]][pickly[l]]=0;
								flag=true;
							}
						}
					}
				}
			}
		}
	}
	printf("%d\n",score);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:16: error: 'fie' was not declared in this scope
   24 |         memset(fie,0,sizeof(fie));
      |                ^~~
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(xindex.begin(),xindex.end(),data[i][j].first)-xindex.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:82: error: reference to 'data' is ambiguous
   46 |                         data[i][j].first=lower_bound(xindex.begin(),xindex.end(),data[i][j].first)-xindex.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(yindex.begin(),yindex.end(),data[i][j].second)-yindex.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:83: error: reference to 'data' is ambiguous
   47 |                         data[i][j].second=lower_bound(yindex.begin(),yindex.end(),data[i][j].second)-yindex.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(n