A - Exponential or Quadratic

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

2^n \gt n^2 ですか?

制約

  • n1 以上 10^9 以下の整数

入力

入力は以下の形式で標準入力から与えられる。

n

出力

2^n \gt n^2 なら Yes を、そうでないなら No を出力せよ。


入力例 1

5

出力例 1

Yes

2^5=32,\ 5^2=25 より 2^n \gt n^2 であるため、Yes を出力します。


入力例 2

2

出力例 2

No

n=2 の場合 2^n=n^2=2^2 となり、故に 2^n \gt n^2 ではありません。よって No を出力します。


入力例 3

623947744

出力例 3

Yes

Score : 100 points

Problem Statement

Does 2^n \gt n^2 hold?

Constraints

  • n is an integer between 1 and 10^9 (inclusive).

Input

Input is given from Standard Input in the following format:

n

Output

If 2^n \gt n^2, print Yes; otherwise, print No.


Sample Input 1

5

Sample Output 1

Yes

Since 2^5=32,\ 5^2=25, we have 2^n \gt n^2, so Yes should be printed.


Sample Input 2

2

Sample Output 2

No

For n=2, we have 2^n=n^2=2^2, so 2^n \gt n^2 does not hold. Thus, No should be printed.


Sample Input 3

623947744

Sample Output 3

Yes
B - Pizza

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

ここに円形のピザが 1 枚あります。
高橋くんは長さ N の数列 A を使ってこのピザを以下の手順で切り分けます。

  • 最初に、円の中心から 12 時の方向に切れ込みをひとつ入れます。
  • 次に、以下の操作を N 回繰り返します。 i 回目の操作では以下を行います。
    • まず、ピザを時計回りに A_i 度回転させる。
    • 次に、円の中心から 12 時の方向に切れ込みをひとつ入れる。

例えば、A=(90,180,45,195) として手順を行うと、下図のようになります。

このとき、最も大きなピザの中心角が何度であるか求めてください。

制約

  • 入力は全て整数
  • 1 \le N \le 359
  • 1 \le A_i \le 359
  • 同じ場所に複数回切れ込みが入ることはない。

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 A_2 \dots A_N

出力

答えを整数として出力せよ。


入力例 1

4
90 180 45 195

出力例 1

120

この入力は問題文中の例と一致します。
最も大きなピザの中心角は 120 度です。


入力例 2

1
1

出力例 2

359

入力例 3

10
215 137 320 339 341 41 44 18 241 149

出力例 3

170

Score : 200 points

Problem Statement

We have a circular pizza.
Takahashi will cut this pizza using a sequence A of length N, according to the following procedure.

  • First, make a cut from the center in the 12 o'clock direction.
  • Next, do N operations. The i-th operation is as follows.
    • Rotate the pizza A_i degrees clockwise.
    • Then, make a cut from the center in the 12 o'clock direction.

For example, if A=(90,180,45,195), the procedure cuts the pizza as follows.

Find the center angle of the largest pizza after the procedure.

Constraints

  • All values in input are integers.
  • 1 \le N \le 359
  • 1 \le A_i \le 359
  • There will be no multiple cuts at the same position.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the answer as an integer.


Sample Input 1

4
90 180 45 195

Sample Output 1

120

This input coincides with the example in the Problem Statement.
The center angle of the largest pizza is 120 degrees.


Sample Input 2

1
1

Sample Output 2

359

Sample Input 3

10
215 137 320 339 341 41 44 18 241 149

Sample Output 3

170
C - digitnum

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

整数 N が与えられるので、以下の問題を解いてください。

f(x)= ( x 以下の正整数で、 x と桁数が同じものの数) とします。
f(1)+f(2)+\dots+f(N)998244353 で割った余りを求めてください。

制約

  • N は整数
  • 1 \le N < 10^{18}

入力

入力は以下の形式で標準入力から与えられる。

N

出力

答えを整数として出力せよ。


入力例 1

16

出力例 1

73
  • 1 以上 9 以下の正整数 x について、 x 以下の整数で、 x と桁数が同じものは 1,2,\dots,x です。
    • これより、 f(1)=1,f(2)=2,...,f(9)=9 となります。
  • 10 以上 16 以下の正整数 x について、 x 以下の整数で、 x と桁数が同じものは 10,11,\dots,x です。
    • これより、 f(10)=1,f(11)=2,...,f(16)=7 となります。

結局、求める答えは 73 です。


入力例 2

238

出力例 2

13870

入力例 3

999999999999999999

出力例 3

762062362

998244353 で割った余りを求めることに注意してください。

Score : 300 points

Problem Statement

Given an integer N, solve the following problem.

Let f(x)= (The number of positive integers at most x with the same number of digits as x).
Find f(1)+f(2)+\dots+f(N) modulo 998244353.

Constraints

  • N is an integer.
  • 1 \le N < 10^{18}

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer as an integer.


Sample Input 1

16

Sample Output 1

73
  • For a positive integer x between 1 and 9, the positive integers at most x with the same number of digits as x are 1,2,\dots,x.
    • Thus, we have f(1)=1,f(2)=2,...,f(9)=9.
  • For a positive integer x between 10 and 16, the positive integers at most x with the same number of digits as x are 10,11,\dots,x.
    • Thus, we have f(10)=1,f(11)=2,...,f(16)=7.

The final answer is 73.


Sample Input 2

238

Sample Output 2

13870

Sample Input 3

999999999999999999

Sample Output 3

762062362

Be sure to find the sum modulo 998244353.

D - AND and SUM

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

T 個のテストケースについて、以下の問題を解いてください。

非負整数 a,s が与えられます。以下の条件を両方とも満たす非負整数の組 (x,y) は存在しますか?

  • x\ \text{AND}\ y=a
  • x+y=s
\text{AND} とは

非負整数 n, m の bit ごとの論理積 n\ \text{AND}\ m は、以下のように定義されます。

  • n\ \text{AND}\ m を二進表記した際の 2^k \, (k \geq 0) の位の数は、n, m を二進表記した際の 2^k の位の数のうち両方1 であれば 1、そうでなければ 0 である。
例えば、4\ \text{AND}\ 6 = 4 となります(二進表記すると: 100\ \text{AND}\ 110 = 100)。

制約

  • 1 \leq T \leq 10^5
  • 0 \leq a,s \lt 2^{60}
  • 入力はすべて整数

入力

入力は標準入力から与えられる。入力の 1 行目は以下の形式である。

T

その後、 T 個のテストケースが続く。各テストケースは以下の形式で与えられる。

a s

出力

T 行出力せよ。i\ (1 \leq i \leq T) 行目には、i 番目に与えられるテストケースについて問題文中の条件を両方とも満たす非負整数の組 (x,y) が存在するなら Yes を、存在しないなら No を出力せよ。


入力例 1

2
1 8
4 2

出力例 1

Yes
No

1 番目のテストケースにおいては、(x,y)=(3,5) などが条件を満たします。

2 番目のテストケースにおいては、条件を満たす非負整数の組 (x,y) は存在しません。


入力例 2

4
201408139683277485 381410962404666524
360288799186493714 788806911317182736
18999951915747344 451273909320288229
962424162689761932 1097438793187620758

出力例 2

No
Yes
Yes
No

Score : 400 points

Problem Statement

Solve the following problem for T test cases.

Given are non-negative integers a and s. Is there a pair of non-negative integers (x,y) that satisfies both of the conditions below?

  • x\ \text{AND}\ y=a
  • x+y=s
What is bitwise \mathrm{AND}?

The bitwise \mathrm{AND} of integers A and B, A\ \mathrm{AND}\ B, is defined as follows:

  • When A\ \mathrm{AND}\ B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if those of A and B are both 1, and 0 otherwise.
For example, we have 4\ \mathrm{AND}\ 6 = 4 (in base two: 100\ \mathrm{AND}\ 110 = 100).

Constraints

  • 1 \leq T \leq 10^5
  • 0 \leq a,s \lt 2^{60}
  • All values in input are integers.

Input

Input is given from Standard Input. The first line is in the following format:

T

Then, T test cases follow. Each test case is in the following format:

a s

Output

Print T lines. The i-th line (1 \leq i \leq T) should contain Yes if, in the i-th test case, there is a pair of non-negative integers (x,y) that satisfies both of the conditions in the Problem Statement, and No otherwise.


Sample Input 1

2
1 8
4 2

Sample Output 1

Yes
No

In the first test case, some pairs such as (x,y)=(3,5) satisfy the conditions.

In the second test case, no pair of non-negative integers satisfies the conditions.


Sample Input 2

4
201408139683277485 381410962404666524
360288799186493714 788806911317182736
18999951915747344 451273909320288229
962424162689761932 1097438793187620758

Sample Output 2

No
Yes
Yes
No
E - Range Sums

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

高橋くんは秘密の整数列 a を持っており、現時点で、a の長さが N であることは分かっています。

a の中身を当てたいあなたに対し、高橋くんは以下の Q 個の情報を追加で与えてくれることを約束しました。

  • i\ (1 \leq i \leq Q) 個目の情報: a_{l_i}+a_{l_i+1}+\cdots+a_{r_i} の値

高橋くんが約束を守り、Q 個の情報すべてが与えられた場合、a に含まれる全要素の総和 a_1+a_2+\cdots+a_N を特定することは可能ですか?

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq \min(2 \times 10^5,\frac{N(N+1)}{2})
  • 1 \leq l_i \leq r_i \leq N
  • (l_i,r_i) \neq (l_j,r_j)\ (i \neq j)
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N Q
l_1 r_1
l_2 r_2
\hspace{0.4cm}\vdots
l_Q r_Q

出力

a に含まれる全要素の総和を特定することが可能なら Yes を、そうでないなら No を出力せよ。


入力例 1

3 3
1 2
2 3
2 2

出力例 1

Yes

1 個目の情報と 2 個目の情報から、a_1+a_2+a_2+a_3 の値が分かります。そこから 3 個目の情報によって得られる a_2 の値を引くと、a_1+a_2+a_3 の値を特定可能です。


入力例 2

4 3
1 3
1 2
2 3

出力例 2

No

a の先頭 3 項の総和を特定することは可能ですが、全要素の総和を特定することは不可能です。


入力例 3

4 4
1 1
2 2
3 3
1 4

出力例 3

Yes

4 個目の情報によって全要素の総和が直接与えられています。

Score : 500 points

Problem Statement

Takahashi has a secret integer sequence a. You know that the length of a is N.

You want to guess the contents of a. He has promised to give you the following Q additional pieces of information.

  • The i-th information: the value a_{l_i}+a_{l_i+1}+\cdots+a_{r_i}.

Is it possible to determine the sum of all elements in a, a_1+a_2+\cdots+a_N, if the Q pieces of promised information are given?

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq \min(2 \times 10^5,\frac{N(N+1)}{2})
  • 1 \leq l_i \leq r_i \leq N
  • (l_i,r_i) \neq (l_j,r_j)\ (i \neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N Q
l_1 r_1
l_2 r_2
\hspace{0.4cm}\vdots
l_Q r_Q

Output

If it is possible to determine the sum of all elements in a, print Yes; otherwise, print No.


Sample Input 1

3 3
1 2
2 3
2 2

Sample Output 1

Yes

From the first and second information, we can find the value a_1+a_2+a_2+a_3. By subtracting the value of a_2 from it, we can determine the value a_1+a_2+a_3.


Sample Input 2

4 3
1 3
1 2
2 3

Sample Output 2

No

We can determine the sum of the first 3 elements of a, but not the sum of all elements.


Sample Input 3

4 4
1 1
2 2
3 3
1 4

Sample Output 3

Yes

The fourth information directly gives us the sum of all elements.

F - Two Exams

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

高橋王国にて、 1 から N までの番号のついた N 人の国民が競技プログラミングの試験に参加しました。
試験は 2 回からなり、人 i1 回目の試験で P_i 位、 2 回目の試験で Q_i 位となりました。
なお、どちらの試験においても、複数人が同じ順位になることはありませんでした。すなわち、順位を表す数列 P,Q はそれぞれ (1,2,...,N) の順列です。

高橋王国の大統領であるいろはちゃんは、この試験の結果に基づいて、 N 人の中から競技プログラミングの世界大会に出場する K 人の代表を決めることになりました。
代表を決めるにあたって、以下が成立していなければなりません。

  • x が代表であり、人 y が代表でないような人の組 (x,y) であって、 P_x > P_y かつ Q_x > Q_y であるようなものが存在してはならない。
    • 言い換えると、 2 回の試験の双方で人 y が人 x よりも小さい順位を取っているにも拘らず、人 x が代表で人 y が代表でないということがあってはならない。

いろはちゃんは、ひとまず上記の条件を満たす代表の選び方の数を知りたいので、この数を求めてください。
ただし、この数は非常に大きくなる場合もあるので、 998244353 で割った余りを出力してください。

制約

  • 入力は全て整数
  • 1 \le N \le 300
  • 1 \le K \le N
  • P,Q(1,2,...,N) の順列である。

入力

入力は以下の形式で標準入力から与えられる。

N K
P_1 P_2 \dots P_N
Q_1 Q_2 \dots Q_N

出力

答えを整数として出力せよ。


入力例 1

4 2
2 4 3 1
2 1 4 3

出力例 1

3
  • 1 と人 2 を代表にすることは問題ありません。
  • 1 と人 3 を代表にすると、双方の試験で人 4 が人 3 よりも小さい順位を取っているため、 (x,y)=(3,4) に対して問題文中の条件に違反します。
  • 1 と人 4 を代表にすることは問題ありません。
  • 2 と人 3 を代表にすると、 (x,y)=(3,1) に対して問題文中の条件に違反します。
  • 2 と人 4 を代表にすることは問題ありません。
  • 3 と人 4 を代表にすると、 (x,y)=(3,1) に対して問題文中の条件に違反します。

結局、求める答えは 3 通りです。


入力例 2

33 16
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
33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

出力例 2

168558757

33 人から 16 人を選ぶ \binom{33}{16} = 1166803110 通りの全てにおいて、問題文中の条件を満たします。
よって、 1166803110998244353 で割った余りである 168558757 を出力することとなります。


入力例 3

15 7
4 9 7 5 6 13 2 11 3 1 12 14 15 10 8
4 14 9 12 7 15 1 2 8 11 3 5 13 6 10

出力例 3

23

Score : 500 points

Problem Statement

In the Kingdom of Takahashi, N citizens numbered 1 to N took an examination of competitive programming.
There were two tests, and Citizen i ranked P_i-th in the first test and Q_i-th in the second test.
There were no ties in either test. That is, each of the sequences P and Q is a permutation of (1, 2, ..., N).

Iroha, the president of the kingdom, is going to select K citizens for the national team at the coming world championship of competitive programming.
The members of the national team must be selected so that the following is satisfied.

  • There should not be a pair of citizens (x, y) where Citizen x is selected and Citizen y is not selected such that P_x > P_y and Q_x > Q_y.
    • In other words, if Citizen y got a rank smaller than that of Citizen x in both tests, it is not allowed to select Citizen x while not selecting Citizen y.

To begin with, Iroha wants to know the number of ways to select citizens for the national team that satisfy the condition above. Find it to help her.
Since this number can be enormous, print it modulo 998244353.

Constraints

  • All values in input are integers.
  • 1 \le N \le 300
  • 1 \le K \le N
  • Each of P and Q is a permutation of (1,2,...,N).

Input

Input is given from Standard Input in the following format:

N K
P_1 P_2 \dots P_N
Q_1 Q_2 \dots Q_N

Output

Print the answer as an integer.


Sample Input 1

4 2
2 4 3 1
2 1 4 3

Sample Output 1

3
  • It is fine to select Citizen 1 and Citizen 2 for the team.
  • If Citizen 1 and Citizen 3 are selected, Citizen 4 ranked higher than Citizen 3 did in both tests, so the pair (x,y)=(3,4) would violate the condition in the Problem Statement.
  • It is fine to select Citizen 1 and Citizen 4.
  • If Citizen 2 and Citizen 3 are selected, the pair (x,y)=(3,1) would violate the condition.
  • It is fine to select Citizen 2 and Citizen 4.
  • If Citizen 3 and Citizen 4 are selected, the pair (x,y)=(3,1) would violate the condition.

The final answer is 3.


Sample Input 2

33 16
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
33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

Sample Output 2

168558757

All \binom{33}{16} = 1166803110 ways of selecting 16 from the 33 citizens satisfy the requirement.
Therefore, we should print 1166803110 modulo 998244353, that is, 168558757.


Sample Input 3

15 7
4 9 7 5 6 13 2 11 3 1 12 14 15 10 8
4 14 9 12 7 15 1 2 8 11 3 5 13 6 10

Sample Output 3

23
G - Cubic?

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 600

問題文

長さ N の数列 A が与えられるので、以下の Q 個の質問に答えてください。

  • i 個目の質問では整数 L_i,R_i が与えられます。 A_{L_i} \times A_{L_i+1} \times \dots \times A_{R_i} は立方数ですか?

ただし、ある正整数 x が立方数であるとは、 x=y^3 を満たすある正整数 y が存在することを言います。

制約

  • 入力は全て整数
  • 1 \le N,Q \le 2 \times 10^5
  • 1 \le A_i \le 10^6
  • 1 \le L_i \le R_i \le N

入力

入力は以下の形式で標準入力から与えられる。

N Q
A_1 A_2 \dots A_N
L_1 R_1
L_2 R_2
\vdots
L_Q R_Q

出力

Q 行出力せよ。
i 行目には、i 個目の質問について A_{L_i} \times A_{L_i+1} \times \dots \times A_{R_i} が立方数なら Yes 、そうでないなら No と出力せよ。
なお、正誤判定器は英大文字と英小文字を区別せず、どちらも受理する。


入力例 1

8 5
7 49 30 1 15 8 6 10
1 2
2 3
4 4
5 8
3 8

出力例 1

Yes
No
Yes
No
Yes
  • 1 個目の質問について、 7 \times 49 = 343 は立方数です。
  • 2 個目の質問について、 49 \times 30 = 1470 は立方数ではありません。
  • 3 個目の質問について、 1 は立方数です。
  • 4 個目の質問について、 15 \times 8 \times 6 \times 10 = 7200 は立方数ではありません。
  • 5 個目の質問について、 30 \times 1 \times 15 \times 8 \times 6 \times 10 = 216000 は立方数です。

Score : 600 points

Problem Statement

Given a sequence A of N numbers, answer the following Q questions.

  • In the i-th question, you are given integers L_i and R_i. Is A_{L_i} \times A_{L_i+1} \times \dots \times A_{R_i} a cubic number?

Here, a positive integer x is said to be a cubic number when there is a positive integer y such that x=y^3.

Constraints

  • All values in input are integers.
  • 1 \le N,Q \le 2 \times 10^5
  • 1 \le A_i \le 10^6
  • 1 \le L_i \le R_i \le N

Input

Input is given from Standard Input in the following format:

N Q
A_1 A_2 \dots A_N
L_1 R_1
L_2 R_2
\vdots
L_Q R_Q

Output

Print Q lines.
The i-th line should contain Yes if, in the i-th question, A_{L_i} \times A_{L_i+1} \times \dots \times A_{R_i} is a cubic number, and No otherwise.
The checker is case-insensitive; output can be either uppercase or lowercase.


Sample Input 1

8 5
7 49 30 1 15 8 6 10
1 2
2 3
4 4
5 8
3 8

Sample Output 1

Yes
No
Yes
No
Yes
  • For the first question, 7 \times 49 = 343 is a cubic number.
  • For the second question, 49 \times 30 = 1470 is not a cubic number.
  • For the third question, 1 is a cubic number.
  • For the fourth question, 15 \times 8 \times 6 \times 10 = 7200 is not a cubic number.
  • For the fifth question, 30 \times 1 \times 15 \times 8 \times 6 \times 10 = 216000 is a cubic number.
Ex - Removing People

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 600

問題文

1 から N までの番号を付けられた N 人の人が、人 1、人 2\cdots、人 N の順に時計回りに円環状に等間隔に並んでいます。 それぞれの人が向いている方向は L または R のみからなる長さ N の文字列 S で表されます。各 i \, (1 \leq i \leq N) に対し、S_i = L ならば人 i は反時計回りの方向を向いており、S_i = R ならば人 i は時計回りの方向を向いています。

以下の操作を N-1 回繰り返します。

  • 残っている人の中から等確率で一人を選び、その人から見て一番手前にいる残っている人を円環から除く。このとき、選んだ人から除かれる人までの距離と同じだけのコストがかかる。

ここで、人 i から人 j (i \neq j) までの距離を以下のように定義します。

  1. i が時計回りの方向を向いている場合
    • i \lt j ならば j-i
    • i \gt j ならば j-i+N
  2. i が反時計回りの方向を向いている場合
    • i \lt j ならば i-j+N
    • i \gt j ならば i-j

合計コストの期待値を\mod 998244353 で求めてください(注記参照)。

注記

求める期待値は必ず有理数となることが証明できます。またこの問題の制約下では、その値を互いに素な 2 つの整数 P, Q を用いて \frac{P}{Q} と表したとき、R \times Q \equiv P\pmod{998244353} かつ 0 \leq R \lt 998244353 を満たす整数 R がただ一つ存在することが証明できます。この R を求めてください。

制約

  • 2 \leq N \leq 300
  • N は整数
  • SLR のみからなる長さ N の文字列

入力

入力は以下の形式で標準入力から与えられる。

N
S

出力

答えを出力せよ。


入力例 1

3
LLR

出力例 1

831870297

求める期待値は \frac{17}{6} です。831870297 \times 6 \equiv 17\pmod{998244353} ですので、831870297 を出力します。

なお、例えば以下のような操作手順が考えられます。

  1. 2 を選ぶ。人 2 から見て一番手前にいる、円環に残っている人は人 1 であるため、人 1 を円環から除く。
  2. 2 をもう一度選ぶ。人 2 から見て一番手前にいる、円環に残っている人は人 3 であるため、人 3 を円環から除く。

この操作手順における合計コストは 3(=1+2) となります。


入力例 2

10
RRRRRRLLRR

出力例 2

460301586

Score : 600 points

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.

  1. When Person i is facing in the clockwise direction:
    • j-i if i \lt j;
    • j-i+N if i \gt j.
  2. 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).

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.

Constraints

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

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the answer.


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.

  1. Person 2 is chosen. The nearest person seen from Person 2 remaining in the circle is Person 1, who gets removed from the circle.
  2. 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