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

using namespace std;

//#define __DEBUG
#define MAX_N 300001
#define RIGHT 'P'
#define LEFT 'L'

int sumRight[MAX_N];
int sumLeft[MAX_N];

int main() {
    ios_base::sync_with_stdio(0);
    int length;
    string seq;

    cin>>length>>seq;

    string::iterator rightIter = seq.begin();
    string::reverse_iterator leftIter = seq.rbegin();
    int* sumRightPtr = &sumRight[0];
    int* sumLeftPtr = &sumLeft[length - 1];

    *sumRightPtr++ = *rightIter++ == RIGHT;
    *sumLeftPtr-- = *leftIter++ == LEFT;
    
    while (rightIter != seq.end()) {
        *sumRightPtr = *(sumRightPtr-1) + (*rightIter++ == RIGHT);
        *sumLeftPtr = *(sumLeftPtr+1) + (*leftIter++ == LEFT);

        ++sumRightPtr;
        --sumLeftPtr;
    }
#ifdef __DEBUG
    for (int i=0;i<length;++i) {
        cout << sumRight[i] << " ";
    }
    cout << endl;
    
    for (int i=0;i<length;++i) {
        cout << sumLeft[i] << " ";
    }
    cout << endl;
#endif
    
    for (int i=0;i<length;++i) {
        if (seq[i] == RIGHT)
            cout << (sumRight[i] > sumLeft[i] ? 2*sumLeft[i] : 2*sumRight[i]-1) << " ";
        else {
            cout << (sumRight[i] >= sumLeft[i] ? 2*sumLeft[i]-1 : 2*sumRight[i]) << " ";
        }
    }
    
}