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
#include <iostream>

int ll[300000];
int lp[300000];
int pl[300000];
int pp[300000];

int main()
{
    int n;
    std::cin >> n;
    char tab[300000];
    for (int i=0; i<n; ++i)
    {
        std::cin >> tab[i];
        if(i>0)
        {
          ll[i]=ll[i-1]+(tab[i-1]=='L');
          lp[i]=lp[i-1]+(tab[i-1]=='P');
        }
    }
    for (int i=n-2; i>=0; --i)
    {
        pl[i]=pl[i+1]+(tab[i+1]=='L');
        pp[i]=pp[i+1]+(tab[i+1]=='P');
    }
    
    for (int i=0; i<n; ++i)
    {
        if(tab[i]=='L')
        {
            if(lp[i]>pl[i])
            {
                std::cout << 2*pl[i]+1 << " ";
            }
            else
            {
                std::cout << 2*lp[i] << " ";
            }
        }
        if(tab[i]=='P')
        {
            if(pl[i]>lp[i])
            {
                std::cout << 2*lp[i]+1 << " ";
            }
            else
            {
                std::cout << 2*pl[i] << " ";
            } 
        }
  
    }
    return 0;
}