#include "bits/stdc++.h" using namespace std; #define all(x) begin(x),end(x) template ostream& operator<<(ostream &os, const pair &p) { return os << '(' << p.first << ", " << p.second << ')'; } template::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #define debug(a) cerr << "(" << #a << ": " << a << ")\n"; typedef long long ll; typedef vector vi; typedef vector vvi; typedef pair pi; const int mxN = 1e5+1, oo = 1e9; int main() { int n; cin >> n; string s; cin >> s; // ac subsequences? // ca doesn't make sense. // try all options // O(n^2) naively vector l(n); int a=0; for(int i=0;i r(n); int c=0; for(int i=n-1;i>=0;--i) { // assume ? replaced by C c+=s[i]=='C' or s[i]=='?'; r[i]+=(s[i]=='A')*c; if(i!=n-1) r[i]+=r[i+1]; } ll ans= max(r[n-1],l[0]); int ql=0, qr = count(all(s),'?')+count(all(s),'C'); for(int i=0;i