#include using namespace std; int main() { int n; cin >> n; string s; cin >> s; vector dp(2); for (int i = 0; i < n; i++){ if (s[i] == 'A'){ dp[0]++; } if (s[i] == 'C'){ dp[1] += dp[0]; } } long long ans = dp[1]; long long r = count(s.begin(), s.end(), 'C') + count(s.begin(), s.end(), '?'); long long l = 0; long long m = 0; if (count(s.begin(), s.end(), '?') == 0){ cout << ans << endl; return 0; } for (int i = 0; i < n; i++){ if (s[i] == 'C'){ r--; } if (s[i] == 'A'){ l++; } if (s[i] == '?'){ r--; l++; } m = max(m, l * r); } ans += m; cout << ans << endl; }