Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
You need to find for every index the number of Bs before it and the number of A's after it
You can speed up the finding of A's and B's in suffix and prefix using preprocessing