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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n;
	string s;
	cin >> n >> s;
	
	vector<int> prefP(n + 2), suffL(n + 2);
	for (int i = 0; i < n; i++) {
		prefP[i + 1] = prefP[i] + (s[i] == 'P');
	}
	for (int i = n - 1; i >= 0; i--) {
		suffL[i + 1] = suffL[i + 2] + (s[i] == 'L');
	}
	
	for (int i = 1; i <= n; i++) {
		int k = min(prefP[i - 1], suffL[i + 1]);
		int ans = k * 2;
		if ((s[i - 1] == 'L' && prefP[i - 1] > k) || (s[i - 1] == 'P' && suffL[i + 1] > k)) {
			ans++;
		}
		cout << ans << (i < n ? " " : "\n");
	}
	
	return 0;
}