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

inline int min(const int a, const int b) {return (a < b ? a : b);}

constexpr int MAX_N = 300000;

int result[MAX_N];

int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int n;
	std::cin >> n;

	std::string str;
	std::cin >> str;

	int right_pref = 0, left_suf = 0;
	for(int i = 0; i < n; ++i)
		left_suf += (str[i] == 'L');

	for(int i = 0; i < n; ++i)
	{
		if(str[i] == 'L')
		{
			left_suf -= (str[i] == 'L');
			result[i] = 2*min(left_suf, right_pref)+(right_pref > left_suf);
		}
		else // str[i] == 'P'
		{
			result[i] = 2*min(left_suf, right_pref)+(right_pref < left_suf);
			right_pref += (str[i] == 'P');
		}
	}

	for(int i = 0; i < n; ++i)
		std::cout << result[i] << ' ';
	std::cout << '\n';

	return 0;
}