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

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    int n, lposition = -1, pposition, add=0;
    std::string letters;

    std::cin >> n;
    std::cin >> letters;
    int result[n];

    for(int i=0;i<n;i++)
    {
        result[i] = 0;
        if(letters[i] == 'L')
            lposition++;
    }
    pposition = lposition + 1;

    for(int i=n-1;i>=0;i--)
    {
        result[i] += add;
        if(letters[i] == 'L')
            add++;
        if(i<=lposition && add > 0)
            add--;
    }

    add = 0;
    for(int i=0;i<n;i++)
    {
        result[i] += add;
        if(letters[i] == 'P')
            add++;
        if(i>=pposition && add > 0)
            add--;
    }

    for(int i=0;i<n;i++)
        std::cout << result[i] << " ";

    return 0;
}