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
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <vector>

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

  size_t count;
  std::cin >> count;
  std::vector<char> chars;
  chars.reserve(count);
  size_t pCount = 0;
  size_t lCount = 0;

  for (int i = 0; i < count; i++) {
    char c;
    std::cin >> c;
    chars.push_back(c);
    if (c == 'P') {
      pCount++;
    } else {
      lCount++;
    }
  }
  count = 0;
  std::vector<size_t> pHelper(1, 0), lHelper(1, 0);

  for (int i = 0; i < lCount; i++) {
    if (chars[i] == 'P') {
      count++;
    }
    pHelper.push_back(count);
  }
  count = 0;
  for (int i = 0; i < pCount; i++) {
    if (chars[chars.size() - i - 1] == 'L') {
      count++;
    }
    lHelper.push_back(count);
  }

  std::vector<size_t> resultL, resultP;
  resultL.reserve(lCount + 1);
  resultP.reserve(pCount + 1);

  for (auto i = 0; i < lCount; i++) {
    resultL.push_back(pHelper[i] * 2 + (chars[i] == 'L' ? 0 : 1));
  }
  for (auto i = 0; i < pCount; i++) {
    resultP.push_back(lHelper[i] * 2 +
                      (chars[chars.size() - i - 1] == 'P' ? 0 : 1));
  }

  for (auto value : resultL) {
    std::cout << value << " ";
  }
  for (auto it = resultP.rbegin(); it != resultP.rend(); it++) {
    std::cout << *it << " ";
  }
  std::cout << "\n";
  return 0;
}