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

bool direction[300000];
int lewa[300000], prawa[300000];
int n;

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

    std::cin >> n;
    char znak;

    for (int i = 0; i < n; i++) {
        std::cin >> znak;
        if (znak == 'P')
            direction[i] = true;
    }

    for (int i = 1; i < n; i++) {
        lewa[i] = lewa[i - 1];
        if (direction[i - 1])
            lewa[i]++;
        prawa[n - i - 1] = prawa[n - i];
        if (!direction[n - i])
            prawa[n - i - 1]++;
    }
    int a, b;

    for (int i = 0; i < n; i++) {
        a = lewa[i] * 2;
        b = prawa[i] * 2;
        if (direction[i])
            a++;
        else
            b++;
        std::cout << std::min(a, b) << ' ';
    }
}