K-Inversions
Time limit10sMemory limit512 MB
For every distance k, count pairs (i,j) with i<j, s[i]='B', s[j]='A', and j-i=k, over a string of up to a million characters.
- Level
Medium7 of 10
- Topics
- Divide and conquer, String, Implementation, Math
- Solved
- No attempts yet
Problem
You are given a string made only of the upper case letters A and B. Let be its length. For an integer , a pair of indices is a -inversion when , , , and .
Take the string BABA. It has two 1-inversions and one 3-inversion, and it has no 2-inversions.

For each from to , report the number of -inversions in .
Input
The first line contains the string . It consists only of the upper case letters A and B, with no spaces. Its length satisfies .
Output
Print lines, each with one integer. The first line holds the number of 1-inversions, the second line the number of 2-inversions, and so on up to the number of -inversions. When , print nothing.