Score : $600$ points
$N$ people numbered $1$ to $N$ are standing in a circle, in the clockwise order of Person $1$, Person $2$, $\cdots$, Person $N$.
The direction each person faces is given by a string $S$ of length $N$. For each $i$ $(1 \leq i \leq N)$, Person $i$ is facing in the counter-clockwise direction if $S_i = $ L
, and clockwise direction if $S_i = $ R
.
The following operation will be repeated $N-1$ times.
Here, the distance from Person $i$ to Person $j$ $(i \neq j)$ is defined as follows.
Find the expected value of the total cost incurred, modulo $998244353$ (see Notes).
It can be proved that the sought expected value is always a rational number. Additionally, under the Constraints of this problem, when that value is expressed as $\frac{P}{Q}$ using two coprime integers $P$ and $Q$, there is a unique integer $R$ such that $R \times Q \equiv P\pmod{998244353}$ and $0 \leq R \lt 998244353$. Find this $R$.
L
and R
.Input is given from Standard Input in the following format:
$N$ $S$
Print the answer.
3 LLR
831870297
The sought expected value is $\frac{17}{6}$. We have $831870297 \times 6 \equiv 17\pmod{998244353}$, so $831870297$ should be printed.
For your reference, here is one possible scenario.
In this case, the total cost incurred is $3(=1+2)$.
10 RRRRRRLLRR
460301586