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

typedef long long LL;

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

    int n;
    cin>>n;

    vector<char> tab(n);
    vector<int> prefL(n+1),prefP(n+1),sufL(n+2),sufP(n+2);

    for(int i=1;i<=n;i++){
        cin>>tab[i];

        prefL[i]=prefL[i-1];
        prefP[i]=prefP[i-1];
        if(tab[i]=='L'){
            prefL[i]++;
        }else{
            prefP[i]++;
        }
    }
    for(int i=n;i>=1;i--){
        sufL[i]=sufL[i+1];
        sufP[i]=sufP[i+1];
        if(tab[i]=='L'){
            sufL[i]++;
        }else{
            sufP[i]++;
        }
    }

    for(int i=1;i<=n;i++){
        if(tab[i]=='L'){
            cout<<min(prefP[i-1],sufL[i+1]+1)+min(prefP[i-1],sufL[i+1])<<" ";
        }else{
            cout<<min(sufL[i+1],prefP[i-1]+1)+min(sufL[i+1],prefP[i-1])<<" ";
        }
    }
    cout<<endl;

    return 0;
}