1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>

using namespace std;
#define MAXN 300010

int add[MAXN];

void update(int p, int k)
{
    add[p]++;
    add[k + 1]--;
    add[p + 1]++;
    add[k]--;
}

void initialize(string &word, int n)
{
    int begin = 0;
    bool first = true;

    for (int i = 0; i < n; ++i)
    {
        if (word[i] == 'P')
        {
            first = false;
        }
        else if (!first)
        {
            update(begin, i);
            begin++;
        }
        else
        {
            begin++;
        }
    }
}

void output(int n)
{
    int current = 0;
    for (int i = 0; i < n; ++i)
    {
        current += add[i];
        cout << current;
        if (i != n - 1)
        {
            cout << " ";
        }
    }
}

int main()
{
    int n;
    string word;

    cin >> n;
    cin >> word;

    initialize(word, n);
    output(n);
}