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
49
50
51
52
#include <iostream>
#include <vector>
#include <utility>

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

  int n;
  std::cin >> n;

  std::vector<char> v(n + 1);
  int a = n / 2;
  for (int i = 0; i < n; ++i) {
    std::cin >> v[i];
    // v[i] = (i < a) ? 'P' : 'L';
  }
  v[n] = 'P';

  std::vector<int> res(n);
  bool changed = true;

  while (changed) {
    changed = false;
    for (int i = 0; i < n; ++i) {
      if (v[i] == 'P' && v[i + 1] == 'L') {
        res[i]++;
        res[i + 1]++;
        std::swap(v[i], v[i + 1]);
        ++i;
        changed = true;
      }
    }
    if (!changed) break;
    for (int i = n - 2; i >= 0; --i) {
      if (v[i] == 'P' && v[i + 1] == 'L') {
        res[i]++;
        res[i + 1]++;
        std::swap(v[i], v[i + 1]);
        --i;
        changed = true;
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    std::cout << res[i] << " ";
  }
  std::cout << "\n";

  return 0;
}