/* -*- coding: utf-8 -*- * * 2276.cc: No.2276 I Want AC - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ typedef long long ll; /* global variables */ char s[MAX_N + 4]; /* subroutines */ /* main */ int main() { int n; scanf("%d%s", &n, s); ll sum = 0; int c = 0; for (int i = 0, a = 0; i < n; i++) { if (s[i] == 'A') a++; else sum += a, c++; } ll maxc = sum; for (int i = 0, a = 0; i < n; i++) { if (s[i] == '?') { sum -= a; a++, c--; sum += c; maxc = max(maxc, sum); } else if (s[i] == 'A') a++; else c--; } printf("%lld\n", maxc); return 0; }