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>

using namespace std;

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

    int n;
    cin >> n;

    int* tab = new int[n];
    char a;
    for(int i = 0; i < n; ++i) {
        cin >> a;
        tab[i] = (a == 'L' ? 0 : 1);
    }

    int* p_on_left = new int[n];
    int curr_p = 0;
    for(int i = 0; i < n; ++i) {
        p_on_left[i] = curr_p;
        if(tab[i] == 1) {
            ++curr_p;
        }
    }

    int* l_on_right = new int[n];
    int curr_l = 0;
    for(int i = n - 1; i >= 0; --i) {
        l_on_right[i] = curr_l;
        if(tab[i] == 0) {
            ++curr_l;
        }
    }

    for(int i = 0; i < n; ++i) {
        cout << 2 * min(p_on_left[i], l_on_right[i]) + (((tab[i] == 1 && (l_on_right[i] > p_on_left[i])) || (tab[i] == 0 && (l_on_right[i] < p_on_left[i]))) ? 1 : 0)  << " ";
    }

    cout << "\n";
    free(tab);
    free(p_on_left);
    free(l_on_right);
    return 0;
}