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
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int m;
    vector<char> o;
    cin >> m;
    
    for(int i=0; i<m; i++){
        char oi;
        cin >> oi;
        o.push_back(oi);
    }
    
    vector<int> p;
    p.push_back(0);

    for(int i=0; i<m; i++){
        if(o[i] == 'P'){
            p.push_back(p[i]+1);
        }else{
            p.push_back(p[i]);
        }
    }
    
    for(int i=0; i<m; i++){
        if(o[i] == 'P'){
            int prawe_L = m - (i + 1) - (p[m]-p[i+1]);
            int lewe_P = p[i] - p[0];
            if(lewe_P < prawe_L){
                cout << lewe_P * 2 + 1 << " ";
            }else{
                cout << prawe_L * 2 << " ";
            }
        }else{
            int lewe_P = p[i] - p[0];
            int prawe_L = m - (i + 1) - (p[m]-p[i+1]);
            if(prawe_L < lewe_P){
                cout << prawe_L * 2 +1 << " ";
            }else{
                cout << lewe_P * 2 << " ";
            }
        }
    }
}