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 <bits/stdc++.h>
using namespace std;


void print(vector<int> &what) {
    for (auto i: what) {
        cout << i << " ";
    }
    cout << "\n";
}

int main()
{
    int size;
    cin >> size;
    string data;
    cin >> data;
    vector<int> leftL(size), leftR(size);
    int l = 0, r = 0;
    for (int i = 0; i<size; i++) {
        if (data[i] == 'L') {
            l++;
        }
        if (data[i] == 'P') {
            r++;
        }
        leftL[i] = l;
        leftR[i] = r;
    }
    
    vector<int> result(size);
    
    for (int i = 0; i < size; i++) {
        int howManyLeftR = i > 0 ? leftR[i-1] : 0;
        int howManyRightL = leftL[size-1] - leftL[i];
        if (data[i] == 'L') {
            result[i] = howManyRightL >= howManyLeftR ? howManyLeftR * 2 : howManyRightL * 2 + 1;
        } else {
            result[i] = howManyLeftR >= howManyRightL ? howManyRightL * 2 : howManyLeftR * 2 + 1; 
        }
    }
    
    print(result);

    return 0;
}