#include #define int long long using namespace std; const int N=2e5+10; int n,m; int g[N],a[N],c[N]; string s; signed main(){ cin>>n>>s; s='#'+s; int res=0; for(int i=1;i<=n;i++){ a[i]=a[i-1],c[i]=c[i-1]; if(s[i]=='A') a[i]++; if(s[i]=='C') c[i]++; if(s[i]!='A') res+=a[i]; } int ans=res; for(int i=1;i<=n;i++){ if(s[i]=='?'){ res-=i-1-c[i-1]; res+=n-i-(a[n]-a[i]); ans=max(ans,res); } } cout<