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
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cout.tie(0); cin.tie(0);
    int n; cin>>n;
    int zerocount = 0;
    vector<bool> in(n, 0); for(int i=0; i<n; i++){char x; cin>>x; if(x == 'P') in[i] = 1; else zerocount++;}
    //-----------------------------
    if(zerocount == 0 || zerocount == n){
        for(int i=0; i<n; i++) cout<<"0 ";
        return 0;
    }
    //-----------------------------
    vector<int> zeropref(n, 0); zeropref[0] = !in[0]; for(int i=1; i<n; i++) zeropref[i] = zeropref[i-1] + !in[i];
    //-----------------------------
    vector<int> results(n, 0);
    for(int i=0; i<zerocount; i++){
        results[i] = 2 * (i + 1 - zeropref[i]); if(in[i] == 1) results[i]--;
    }
    for(int i=zerocount; i<n; i++){
        results[i] = 2 * (zeropref[n-1] - zeropref[i-1]); if(in[i] == 0) results[i]--;
    }
    //-----------------------------
    for(auto e: results) cout<<e<<" ";
    return 0;
}