#ABC238H. [ABC238Ex] Removing People

[ABC238Ex] Removing People

Score : 600600 points

Problem Statement

NN people numbered 11 to NN are standing in a circle, in the clockwise order of Person 11, Person 22, \cdots, Person NN. The direction each person faces is given by a string SS of length NN. For each ii (1iN)(1 \leq i \leq N), Person ii is facing in the counter-clockwise direction if Si=S_i = L, and clockwise direction if Si=S_i = R.

The following operation will be repeated N1N-1 times.

  • Choose one of the remaining people with equal probability, and remove from the circle the nearest person seen from the chosen person. This incurs a cost equal to the distance from the chosen person to the removed person.

Here, the distance from Person ii to Person jj (ij)(i \neq j) is defined as follows.

  1. When Person ii is facing in the clockwise direction:- jij-i if i<ji \lt j;
    • ji+Nj-i+N if i>ji \gt j.
  2. When Person ii is facing in the counter-clockwise direction:- ij+Ni-j+N if i<ji \lt j;
    • iji-j if i>ji \gt j.

Find the expected value of the total cost incurred, modulo 998244353998244353 (see Notes).

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 PQ\frac{P}{Q} using two coprime integers PP and QQ, there is a unique integer RR such that R×QP(mod998244353)R \times Q \equiv P\pmod{998244353} and 0R<9982443530 \leq R \lt 998244353. Find this RR.

Constraints

  • 2N3002 \leq N \leq 300
  • NN is an integer.
  • SS is a string of length NN consisting of L and R.

Input

Input is given from Standard Input in the following format:

NN

SS

Output

Print the answer.

3
LLR
831870297

The sought expected value is 176\frac{17}{6}. We have 831870297×617(mod998244353)831870297 \times 6 \equiv 17\pmod{998244353}, so 831870297831870297 should be printed.

For your reference, here is one possible scenario.

  1. Person 22 is chosen. The nearest person seen from Person 22 remaining in the circle is Person 11, who gets removed from the circle.
  2. Person 22 is chosen again. The nearest person seen from Person 22 remaining in the circle is Person 33, who gets removed from the circle.

In this case, the total cost incurred is 3(=1+2)3(=1+2).

10
RRRRRRLLRR
460301586