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
//
// Created by piotr on 06.03.2024.
//
#include <cassert>
#include <cstdio>

char X[300000];
int LzPrawej[300000];
int PzLewej[300000];

int wtf(int a, int b) {
    return (a>b) ? 2*b+1 : 2*a;
}

int oblicz(int i) {
    if (X[i] == 'L') {
        return wtf(PzLewej[i], LzPrawej[i]);
    } else {
        return wtf(LzPrawej[i], PzLewej[i]);
    }
}

int main()
{
    int N;
    assert(scanf("%d\n", &N) == 1);
    assert(fread(X, N, 1, stdin) == 1);

    PzLewej[0] = 0;
    for (int i=1; i<N; ++i) {
        PzLewej[i] = PzLewej[i-1] + (X[i-1] == 'P');
    }
    LzPrawej[N-1] = 0;
    for (int i=N-2; i>=0; --i) {
        LzPrawej[i] = LzPrawej[i+1] + (X[i+1] == 'L');
    }

    printf("%d", oblicz(0));
    for (int i=1; i<N; ++i) {
        printf(" %d", oblicz(i));
    }
    putchar('\n');
}