Language: C++

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;
string a[10005];
int check[10005],n;
void DFS(int i,long long &res,int start){
	int chon=0;
    for(int j=1;j<=n;j++){

        if(check[j]==0){
            //cout<<i<<" "<<start<<" "<<j<<" "<<a[i][a[i].size()-1]<<" "<<a[j][0]<<endl;
            if(start==0){
            	if((a[i][a[i].size()-1]=='A')&&((a[j][0]=='B'))){
                    res++;
                    check[j]=1;
	                chon=j;

	                break;
                }


            }
            else{
                if((a[i][0]=='B')&&((a[j][a[j].size()-1]=='A'))){
                    res++;
                    check[j]=1;
	                chon=j;
	                //cout<<i<<" "<<start<<" "<<j<<endl;
	                break;
                }
            }
        }
    }
    if(chon!=0){
    	//cout<<i<<" "<<chon<<endl;
    	DFS(chon,res,start);
    }
}
int main()
{
    long long ans=0;
    cin>>n;
    vector<int>v;
    int start=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if((a[i][a[i].size()-1]=='A')||(a[i][0]=='B')){
            v.push_back(i);
        }
        if((a[i][a[i].size()-1]=='A')&&(a[i][0]=='B')){
            start=i;
        }
        for(int j=1;j<a[i].size();j++){
            if((a[i][j]=='B')&&(a[i][j-1]=='A')){
                ans++;
            }
        }
    }
    if(start!=0){
        check[start]=1;
        DFS(start,ans,0);
        DFS(start,ans,1);
    }
    //cout<<start<<endl;
    int kt=0;

	for(int i=0;i<v.size();i++){
		start=v[i];
        if(check[start]==0){
        	check[start]=1;
        	int temp=ans;
        	/*if(kt==0){
                if((a[start][a[start].size()-1]=='A')&&(a[start][0]=='B'))
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
                kt=1;
                continue;
        	}*/
            if(a[start][a[start].size()-1]=='A'){
                DFS(start,ans,0);
                if(ans==temp){
                    check[start]=0;
                }
                //continue;
            }
            if(a[start][0]=='B'){
                DFS(start,ans,1);
                if(ans==temp){
                    check[start]=0;
                }
               // continue;
            }

        }
    }
    cout<<ans<<endl;
}



Compiler output:
a.cc:108:8: error: redefinition of 'std::string a [10005]'
  108 | string a[10005];
      |        ^
a.cc:4:8: note: 'std::string a [10005]' previously declared here
    4 | string a[10005];
      |        ^
a.cc:109:5: error: redefinition of 'int check [10005]'
  109 | int check[10005],n;
      |     ^~~~~
a.cc:5:5: note: 'int check [10005]' previously declared here
    5 | int check[10005],n;
      |     ^~~~~
a.cc:109:18: error: redefinition of 'int n'
  109 | int check[10005],n;
      |                  ^
a.cc:5:18: note: 'int n' previously declared here
    5 | int check[10005],n;
      |                  ^
a.cc:110:6: error: redefinition of 'void DFS(int, long long int&, int)'
  110 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:6:6: note: 'void DFS(int, long long int&, int)' previously defined here
    6 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:143:5: error: redefinition of 'int main()'
  143 | int main()
      |     ^~~~
a.cc:39:5: note: 'int main()' previously defined here
   39 | int main()
      |     ^~~~
a.cc:212:8: error: redefinition of 'std::string a [10005]'
  212 | string a[10005];
      |        ^
a.cc:4:8: note: 'std::string a [10005]' previously declared here
    4 | string a[10005];
      |        ^
a.cc:213:5: error: redefinition of 'int check [10005]'
  213 | int check[10005],n;
      |     ^~~~~
a.cc:5:5: note: 'int check [10005]' previously declared here
    5 | int check[10005],n;
      |     ^~~~~
a.cc:213:18: error: redefinition of 'int n'
  213 | int check[10005],n;
      |                  ^
a.cc:5:18: note: 'int n' previously declared here
    5 | int check[10005],n;
      |                  ^
a.cc:214:6: error: redefinition of 'void DFS(int, long long int&, int)'
  214 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:6:6: note: 'void DFS(int, long long int&, int)' previously defined here
    6 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:247:5: error: redefinition of 'int main()'
  247 | int main()
      |     ^~~~
a.cc:39:5: note: 'int main()' previously defined here
   39 | int main()
      |     ^~~~
a.cc:316:8: error: redefinition of 'std::string a [10005]'
  316 | string a[10005];
      |        ^
a.cc:4:8: note: 'std::string a [10005]' previously declared here
    4 | string a[10005];
      |        ^
a.cc:317:5: error: redefinition of 'int check [10005]'
  317 | int check[10005],n;
      |     ^~~~~
a.cc:5:5: note: 'int check [10005]' previously declared here
    5 | int check[10005],n;
      |     ^~~~~
a.cc:317:18: error: redefinition of 'int n'
  317 | int check[10005],n;
      |                  ^
a.cc:5:18: note: 'int n' previously declared here
    5 | int check[10005],n;
      |                  ^
a.cc:318:6: error: redefinition of 'void DFS(int, long long int&, int)'
  318 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:6:6: note: 'void DFS(int, long long int&, int)' previously defined here
    6 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:351:5: error: redefinition of 'int main()'
  351 | int main()
      |     ^~~~
a.cc:39:5: note: 'int main()' previously defined here
   39 | int main()
      |     ^~~~
a.cc:420:8: error: redefinition of 'std::string a [10005]'
  420 | string a[10005];
      |        ^
a.cc:4:8: note: 'std::string a [10005]' previously declared here
    4 | string a[10005];
      |        ^
a.cc:421:5: error: redefinition of 'int check [10005]'
  421 | int check[10005],n;
      |     ^~~~~
a.cc:5:5: note: 'int check [10005]' previously declared here
    5 | int check[10005],n;
      |     ^~~~~
a.cc:421:18: error: redefinition of 'int n'
  421 | int check[10005],n;
      |                  ^
a.cc:5:18: note: 'int n' previously declared here
    5 | int check[10005],n;
      |                  ^
a.cc:422:6: error: redefinition of 'void DFS(int, long long int&, int)'
  422 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:6:6: note: 'void DFS(int, long long int&, int)' previously defined here
    6 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:455:5: error: redefinition of 'int main()'
  455 | int main()
      |     ^~~~
a.cc:39:5: note: 'int main()' previously defined here
   39 | int main()
      |     ^~~~
a.cc:524:8: error: redefinition of 'std::string a [10005]'
  524 | string a[10005];
      |        ^
a.cc:4:8: note: 'std::string a [10005]' previously declared here
    4 | string a[10005];
      |        ^
a.cc:525:5: error: redefinition of 'int check [10005]'
  525 | int check[10005],n;
      |     ^~~~~
a.cc:5:5: note: 'int check [10005]' previously declared here
    5 | int check[10005],n;
      |     ^~~~~
a.cc:525:18: error: redefinition of 'int n'
  525 | int check[10005],n;
      |                  ^
a.cc:5:18: note: 'int n' previously declared here
    5 | int check[10005],n;
      |                  ^
a.cc:526:6: error: redefinition of 'void DFS(int, long long int&, int)'
  526 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:6:6: note: 'void DFS(int, long long int&, int)' previously defined here
    6 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:559:5: error: redefinition of 'int main()'
  559 | int main()
      |     ^~~~
a.cc:39:5: note: 'int main()' previously defined here
   39 | int main()
      |     ^~~~
a.cc:628:8: error: redefinition of 'std::string a [10005]'
  628 | string a[10005];
      |        ^
a.cc:4:8: note: 'std::string a [10005]' previously declared here
    4 | string a[10005];
      |        ^
a.cc:629:5: error: redefinition of 'int check [10005]'
  629 | int check[10005],n;
      |     ^~~~~
a.cc:5:5: note: 'int check [10005]' previously declared here
    5 | int check[10005],n;
      |     ^~~~~
a.cc:629:18: error: redefinition of 'int n'
  629 | int check[10005],n;
      |                  ^
a.cc:5:18: note: 'int n' previously declared here
    5 | int check[10005],n;
      |                  ^
a.cc:630:6: error: redefinition of 'void DFS(int, long long int&, int)'
  630 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:6:6: note: 'void DFS(int, long long int&, int)' previously defined here
    6 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:663:5: error: redefinition of 'int main()'
  663 | int main()
      |     ^~~~
a.cc:39:5: note: 'int main()' previously defined here
   39 | int main()
      |     ^~~~
a.cc:732:8: error: redefinition of 'std::string a [10005]'
  732 | string a[10005];
      |        ^
a.cc:4:8: note: 'std::string a [10005]' previously declared here
    4 | string a[10005];
      |        ^
a.cc:733:5: error: redefinition of 'int check [10005]'
  733 | int check[10005],n;
      |     ^~~~~
a.cc:5:5: note: 'int check [10005]' previously declared here
    5 | int check[10005],n;
      |     ^~~~~
a.cc:733:18: error: redefinition of 'int n'
  733 | int check[10005],n;
      |                  ^
a.cc:5:18: note: 'int n' previously declared here
    5 | int check[10005],n;
      |                  ^
a.cc:734:6: error: redefinition of 'void DFS(int, long long int&, int)'
  734 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:6:6: note: 'void DFS(int, long long int&, int)' previously defined here
    6 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:767:5: error: redefinition of 'int main()'
  767 | int main()
      |     ^~~~
a.cc:39:5: note: 'int main()' previously defined here
   39 | int main()
      |     ^~~~
a.cc:836:8: error: redefinition of 'std::string a [10005]'
  836 | string a[10005];
      |        ^
a.cc:4:8: note: 'std::string a [10005]' previously declared here
    4 | string a[10005];
      |        ^
a.cc:837:5: error: redefinition of 'int check [10005]'
  837 | int check[10005],n;
      |     ^~~~~
a.cc:5:5: note: 'int check [10005]' previously declared here
    5 | int check[10005],n;
      |     ^~~~~
a.cc:837:18: error: redefinition of 'int n'
  837 | int check[10005],n;
      |                  ^
a.cc:5:18: note: 'int n' previously declared here
    5 | int check[10005],n;
      |                  ^
a.cc:838:6: error: redefinition of 'void DFS(int, long long int&, int)'
  838 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:6:6: note: 'void DFS(int, long long int&, int)' previously defined here
    6 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:871:5: error: redefinition of 'int main()'
  871 | int main()
      |     ^~~~
a.cc:39:5: note: 'int main()' previously defined here
   39 | int main()
      |     ^~~~
a.cc:940:8: error: redefinition of 'std::string a [10005]'
  940 | string a[10005];
      |        ^
a.cc:4:8: note: 'std::string a [10005]' previously declared here
    4 | string a[10005];
      |        ^
a.cc:941:5: error: redefinition of 'int check [10005]'
  941 | int check[10005],n;
      |     ^~~~~
a.cc:5:5: note: 'int check [10005]' previously declared here
    5 | int check[10005],n;
      |     ^~~~~
a.cc:941:18: error: redefinition of 'int n'
  941 | int check[10005],n;
      |                  ^
a.cc:5:18: note: 'int n' previously declared here
    5 | int check[10005],n;
      |                  ^
a.cc:942:6: error: redefinition of 'void DFS(int, long long int&, int)'
  942 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:6:6: note: 'void DFS(int, long long int&, int)' previously defined here
    6 | void DFS(int i,long long &res,int start){
      |      ^~~
a.cc:975:5: error: redefinition of 'int main()'
  975 | int main()
      |     ^~~~
a.cc:39:5: note: 'int main()' previously defined here
   39 | int main()
      |     ^~~~
a.cc:1044:8: error: redefinition of 'std::string a [10005]'
 1044 | string a[10005];
      |        ^
a.cc:4:8: note: 'std::string a [10005]' previously declared here
    4 | string a[10005];
      |        ^
a.cc:1045:5: error: redefinition of 'int check [10005]'
 1045 | int check[10005],n;
      |     ^~~~~
a.cc:5:5: note: 'int check [10005]' previously declared here
    5 | int check[10005],n;
      |     ^~~~~
a.cc:1045:18: error: redefinition of 'int n'
 1045 | int check[10005],n;
      |                  ^
a.cc:5:18: note: 'int n' previ