#include #include int main() { long long A = 0, C = 0, a = 0, n = 0; char L = 'A'; std::string S; std::cin >> S; // Assuming the first input is not used as per the Python code for (char s : S) { if (s == L) { A += 1; } else { C += 1; n += A; } } long long c = C; long long m = n; for (char s : S) { if (s < L) { n += c - 1 - a; a += 1; c -= 1; } c -= s > L; a += s == L; m = std::max(n, m); } std::cout << m << std::endl; return 0; }