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
56
57
58
/* 2024
 * Maciej Szeptuch
 */
#include <cstdio>

const int MAX_ANTS = 300001;

int ants;
char side[MAX_ANTS];
int total_right;
int current_right;

inline int after_right(int position)
{
    return total_right - current_right - (side[position] == 'P');
}

inline int after_left(int position)
{
    return ants - position - 1 - after_right(position);
}

inline int hits(int forward, int backward)
{
    if(forward == 0)
        return 0;

    if(backward == 0)
        return 1;

    if(forward <= backward)
        return 2 * forward;

    return 2 * backward + 1;
}

int main(void)
{
    scanf("%d %s", &ants, side);
    for(int a = 0; a < ants; ++a)
        total_right += side[a] == 'P';

    for(int a = 0; a < ants; ++a)
    {
        if(side[a] == 'P')
        {
            printf("%d ", hits(after_left(a), current_right));
            current_right += 1;
        }

        else
            printf("%d ", hits(current_right, after_left(a)));
    }

    puts("");

    return 0;
}