#include using namespace std; #define rep(i,n) for (long long i=0;i<(long long)(n);i++) #define all(v) v.begin(),v.end() using ll=long long; using pll=pair; using tll=tuple; const ll INF=(1ll<<60); template void chmin(T &a,T b){ if(a>b){ a=b; } } template void chmax(T &a,T b){ if(a> n; string s; cin >> s; ll la=0,rc=0; ll now=0; rep(i,n){ if(s[i]=='A') la++; else{ now+=la; rc++; } } la=0; ll ans=now; rep(i,n){ if(s[i]=='A') la++; if(s[i]=='C') rc--; if(s[i]=='?'){ rc--; now-=la; la++; now+=rc; chmax(ans,now); } } cout << ans << '\n'; }