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 std::cin, std::cout, std::string;

void init_io() {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
}

int main() {
  init_io();

  size_t n;
  cin >> n;

  string directions;
  cin >> directions;
  assert(directions.size() == n);

  size_t left = 0;
  size_t right = std::count(directions.begin(), directions.end(), 'L');

  for (const char dir: directions) {
    size_t val;
    if (dir == 'L') {
      right -= 1;
      val = std::min(2 * left, 2 * right + 1);
    } else if (dir == 'P') {
      val = std::min(2 * right, 2 * left + 1);
      left += 1;
    } else {
      assert(false);
    }
    std::cout << val << " ";
  }

  cout << "\n";
}