#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; const int MR=2e5+10; int n; string s; int a[MR],c[MR]; int main(){ cin>>n>>s; LL sum=0; for(int i=1;i<=n;i++){ a[i]=a[i-1]; if(s[i-1]=='A') a[i]++; c[i]=c[i-1]; if(s[i-1]=='C'){ c[i]++; } if(s[i-1]!='A') sum+=a[i-1]; } LL ans=sum; //printf("i=%d sum=%lld\n",0,sum); for(int i=1;i<=n;i++){ if(s[i-1]=='?'){ sum-=i-1-c[i-1]; sum+=n-i-(a[n]-a[i]); } //printf("i=%d sum=%lld\n",i,sum); ans=max(ans,sum); } cout<