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
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300009;
int p[maxn] , s[maxn];
string S;

int main()
{
    int n ;
    cin >> n;
    cin >> S;
    S = '&'+S;
    for(int i = 1 ; i <= n ;i++)
    {
        p[i] = p[i-1];
        if(S[i] == 'P')p[i]++;
    }

    for(int i = n ; i > 0 ;i--)
    {
        s[i] = s[i+1];
        if(S[i] == 'L')s[i]++;
    }

    for(int i = 1 ; i <= n;  i++)
    {
        if(S[i] == 'L')
        {
            cout << min(p[i-1]*2 , s[i+1]*2+1) << ' ';
        }
        else
        {
            cout << min(p[i-1]*2+1 , s[i+1]*2) << ' ';

        }
    }
    
    return 0;
}