#P7912. Fruit Basket Simulation
Fruit Basket Simulation
Fruit Basket Simulation
Little Bear has a row of \(n\) fruits in his shop, numbered from \(1\) to \(n\). Each fruit is either an apple or an orange. A block is defined as a maximal contiguous segment of identical fruits. Little Bear will fill several baskets with the fruits by performing the following operation repeatedly: in each operation, he picks the leftmost fruit from every block simultaneously and puts these fruits into one basket. After removing these fruits, the remaining ones shift together; if two segments of the same fruit type become adjacent because of removals, they merge into one block. The process continues until all fruits are picked. Your task is to compute, in order, the number of fruits contained in each basket.
Note: All formulas are in LaTeX format, e.g. \(n, 1,2,\ldots,n\).
inputFormat
The input consists of two lines. The first line contains a positive integer \(n\) \((1 \leq n \leq 10^5)\), the number of fruits. The second line contains a string of length \(n\) composed only of the characters 'A' and 'O', representing apples and oranges respectively.
outputFormat
Output a single line containing the number of fruits in each basket (in order of formation), separated by spaces.
sample
5
AAOOA
3 2