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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#if defined(EMBE_DEBUG) && !defined(NDEBUG)
#include "embe-debug.hpp"
#else
#define LOG_INDENT(...) do {} while (false)
#define LOG(...) do {} while (false)
#define DUMP(...) do {} while (false)
#endif

#include <algorithm>
#include <iostream>
#include <iterator>
#include <ranges>
#include <vector>
using namespace std;

namespace {

enum class Direction {
  LEFT,
  RIGHT,
};

istream& operator>>(istream& is, Direction& dir) {
  char c;
  is >> c;
  if (c == 'L') dir = Direction::LEFT;
  else if (c == 'P') dir = Direction::RIGHT;
  else is.setstate(ios::failbit);
  return is;
}

ostream& operator<<(ostream& os, Direction dir) {
  return os << (dir == Direction::LEFT ? 'L' : 'P');
}

template <ranges::forward_range R>
vector<int> solve(R ants) {
  int left = 0;
  int right = 0;
  for (auto const& d: ants) {
    if (d == Direction::LEFT) ++right;
  }
  vector<int> res;
  res.reserve(ants.size());
  for (auto const& d: ants) {
    if (d == Direction::LEFT) --right;

    auto both = min(left, right);
    auto cur = 2 * both;

    if (d == Direction::LEFT && left > both || d == Direction::RIGHT && right > both) {
      ++cur;
    }

    res.push_back(cur);

    if (d == Direction::RIGHT) ++left;
  }
  return res;
}

}

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

  int n;
  cin >> n;

  auto ants_range = views::counted(istream_iterator<Direction>{cin}, n) | views::common;

  auto ants = vector(ants_range.begin(), ants_range.end());

  auto res = solve(ants);
  bool first = true;
  for (auto const& x: res) {
    if (first) first = false;
    else cout << ' ';
    cout << x;
  }
  cout << endl;

  return 0;
}