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
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a; i<=b; ++i)

constexpr int baseN =1<<19;
int N, rres[2][2*baseN], posEnd[baseN];
bitset<baseN> inp;

int GetSum(int v, bool dim){
    v+=baseN;
    int res=0;
    while(v){
        res+=rres[dim][v];
        v/=2;
    }
    return res;
}
void Add(int p, int q, int val, int dim){
    p+=baseN-1, q+=baseN+1;
    while(p/2!=q/2){
        if(p%2==0) rres[dim][p+1]+=val;
        if(q%2==1) rres[dim][q-1]+=val;
        q/=2, p/=2;
    }
}
void Input(){
    string cInp;
    int cPos=0;
    cin>>N>>cInp;
    FOR(i,0,N-1){
        if(cInp[i]=='P') inp[i]=1;
        else posEnd[i]=cPos++;
    }
    FOR(i,0,N-1)
        if(inp[i]) posEnd[i]=cPos++;
}
void Print(){
    FOR(i,0,N-1)
        cout<<GetSum(i,inp[i])<<' ';
    cout<<'\n';
}
void Solve(){
    FOR(i,0,N-1){
        if(inp[i]){
            Add(i+1,posEnd[i]-1,2,0);
            Add(posEnd[i],posEnd[i],1,0);
        }else{
            Add(posEnd[i]+1,i-1,2,1);
            Add(posEnd[i],posEnd[i],1,1);
        }
    }
}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    Input();
    Solve();
    Print();
}