Language: C++

#include <bits/stdc++.h>
using namespace std;
long long n;
bool cmp1(pair < int , pair < string , pair < char , char > > > tmp1,pair < int , pair < string , pair < char , char > > > tmp2)
{
    return tmp1.second.second.first<tmp2.second.second.first;
}
bool cmp2(pair < int , pair < string , pair < char , char > > > tmp1,pair < int , pair < string , pair < char , char > > > tmp2)
{
    return tmp1.second.second.second<tmp2.second.second.second;
}
long long mini(long long a,long long b)
{
    return a<b?a:b;
}
long long maxi(long long a,long long b)
{
    return a>b?a:b;
}
void solve()
{
    long long i,j,ans=0,res=0,res1=0,res2=0;
    vector < pair < int , pair < string , pair < char , char > > > > in(n);
    for (i=0;i<n;i++)
    {
        cin>>in[i].second.first;
        in[i].first=0;
        long long l=in[i].second.first.length();
        if (l>1)
        {
            for (j=1;j<l;j++)
                if (in[i].second.first[j]=='B'&&in[i].second.first[j-1]=='A') ans++;
        }
        in[i].second.second.first=in[i].second.first[0];
        in[i].second.second.second=in[i].second.first[l-1];
    }
    for (i=0;i<n;i++)
        if (in[i].second.second.first=='B'&&in[i].second.second.second=='A') {in[i].first=1;res++;}
    for (i=0;i<n;i++)
        if (!in[i].first&&in[i].second.second.second=='A') res1++;
    for (i=0;i<n;i++)
        if (!in[i].first&&in[i].second.second.first=='B') res2++;
    //cout<<ans<<"      "<<res<<"   "<<mini(res1,res2)<<endl;
    if (res1&&res2) cout<<ans+res+1+mini(res1-1,res2-1);
    else if (res1&&!res2) cout<<ans+res;
    else if (!res1&&res2) cout<<ans+res;
    else cout<<ans+max(0,res-1);
    cout<<endl;
}
int main()
{
    while(cin>>n)
         solve();
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:47:23: error: no matching function for call to 'max(int, long long int)'
   47 |     else cout<<ans+max(0,res-1);
      |                    ~~~^~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:47:23: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   47 |     else cout<<ans+max(0,res-1);
      |                    ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:47:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   47 |     else cout<<ans+max(0,res-1);
      |                    ~~~^~~~~~~~~