This page is still under construction.

Parts of this page are still being built. What you see may change.

K-Inversions

Time limit10sMemory limit512 MB

Summary
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 ss made only of the upper case letters A and B. Let nn be its length. For an integer kk, a pair of indices (i,j)(i, j) is a kk-inversion when 1≤i<j≤n1 \le i < j \le n, s[i]=Bs[i] = \text{B}, s[j]=As[j] = \text{A}, and j−i=kj - i = k.

Take the string BABA. It has two 1-inversions and one 3-inversion, and it has no 2-inversions.

For each kk from 11 to n−1n - 1, report the number of kk-inversions in ss.

Input

The first line contains the string ss. It consists only of the upper case letters A and B, with no spaces. Its length nn satisfies 1≤n≤1 000 0001 \le n \le 1\,000\,000.

Output

Print n−1n - 1 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 (n−1)(n - 1)-inversions. When n=1n = 1, print nothing.

Examples2

  1. Example 1

    Input
    BABA
    
    Expected output
    2
    0
    1
    
  2. Example 2

    Input
    BBBBBAAAAA
    
    Expected output
    1
    2
    3
    4
    5
    4
    3
    2
    1