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

using namespace std;

const int MAX = 3e5+7;
int pref[MAX]; //ile P na prefie
int suf[MAX]; //ile L na sufie

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	string s;
	cin >> n >> s;
	pref[0] = (s[0]=='P');
	for (int i = 1; i < n; i++)
		pref[i] = pref[i-1] + (s[i]=='P');
	suf[n-1] = (s[n-1]=='L');
	for (int i = n-2; i >= 0; i--)
		suf[i] = suf[i+1] + (s[i]=='L');

	int poczatekP = n - pref[n-1];

	for (int i = 0; i < n; i++) {
		int x = min(pref[i], suf[i]);
		bool L0 = (s[i]=='L');
		bool L1 = (i < poczatekP);
		int koszt = (L0 == L1);
		cout << 2*x-1 + koszt << ' ';
	}
	cout << '\n';

	return 0;
}