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
#include <iostream>
using namespace std;

int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int *l = new int[n];
	int *p = new int[n];
	int c=0;
	for(int i=0;i<n;i++){
		p[i]=c;
		if(s[i]=='P') c++;
	}
	c=0;
	for(int i=n-1;i>=0;i--){
		l[i]=c;
		if(s[i]=='L') c++;
	}

	for(int i=0;i<n;i++){
		int ll=l[i],pp=p[i];
		char ss = s[i];
		//cout<<ll<<":"<<pp<<" "<<ss<<endl;
		cout<<(s[i]=='L'?pp<ll?pp*2:ll*2+1:ll<pp?ll*2:pp*2+1)<<" ";
	}
}