#include using namespace std; int main() { int n; cin >> n; string s; cin >> s; string t = s; for (int i = 0; i < n; i++){ if (t[i] == '?'){ t[i] = 'C'; } } vector dp(2); for (int i = 0; i < n; i++){ if (t[i] == 'A'){ dp[0]++; } if (t[i] == 'C'){ dp[1] += dp[0]; } } long long m = dp[1]; long long ans = m; vector a(n + 1); vector b(n + 1); for (int i = 1; i <= n; i++){ if (t[i - 1] == 'A' or s[i - 1] == '?'){ a[i]++; } if (t[i - 1] == 'C' or s[i - 1] == '?'){ b[i]++; } a[i] += a[i - 1]; b[i] += b[i - 1]; } for (int i = 0; i < n; i++){ if (s[i] == '?'){ m -= a[i]; m += b[n] - b[i + 1]; } ans = max(ans, m); } cout << ans << endl; }