P25759 [AtCoder] Removing People
NOI
题目描述

Problem Statement

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.

  • 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 i to Person $j (i \neq j)$ is defined as follows.

  • When Person i is facing in the clockwise direction:
  • j-i if $i \lt j$;
  • j-i+N if $i \gt j$.

  • When Person i is facing in the counter-clockwise direction:

  • i-j+N if $i \lt j$;
  • i-j if $i \gt j$.

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

Input

Input is given from Standard Input in the following format:
N
S

Output

Print the answer.

Constraints

  • $2 \leq N \leq 300$
  • N is an integer.
  • S is a string of length N consisting of L and R.

Sample Input 1

3
LLR

Sample Output 1

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.

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

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

Sample Input 2

10
RRRRRRLLRR

Sample Output 2

460301586

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 LLR
样例输出
831870297