A - New Scheme

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

8 個の整数 S_1,S_2,\dots,S_8 が与えられます。 以下の 3 つの条件が全て満たされるならば Yes を、そうでないならば No を出力してください。

  • 数列 (S_1,S_2,\dots,S_8) は広義単調増加である。すなわち、S_1 \leq S_2 \leq \dots \leq S_8 である。
  • S_1,S_2,\dots,S_8 は全て 100 以上 675 以下である。
  • S_1,S_2,\dots,S_8 は全て 25 の倍数である。

制約

  • 0\leq S_i \leq 1000
  • 入力は全て整数

入力

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

S_1 S_2 \dots S_8

出力

答えを出力せよ。


入力例 1

125 175 250 300 400 525 600 650

出力例 1

Yes

3 つの条件を全て満たしています。


入力例 2

100 250 300 400 325 575 625 675

出力例 2

No

S_4 > S_5 であるため、1 つ目の条件を満たしていません。


入力例 3

0 23 24 145 301 413 631 632

出力例 3

No

2 つ目の条件と 3 つ目の条件を満たしていません。

Score : 100 points

Problem Statement

Given eight integers S_1,S_2,\dots, and S_8, print Yes if they satisfy all of the following three conditions, and No otherwise.

  • The sequence (S_1,S_2,\dots,S_8) is monotonically non-decreasing. In other words, S_1 \leq S_2 \leq \dots \leq S_8.
  • S_1,S_2,\dots, and S_8 are all between 100 and 675, inclusive.
  • S_1,S_2,\dots, and S_8 are all multiples of 25.

Constraints

  • 0\leq S_i \leq 1000
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

S_1 S_2 \dots S_8

Output

Print the answer.


Sample Input 1

125 175 250 300 400 525 600 650

Sample Output 1

Yes

They satisfy all of the three conditions.


Sample Input 2

100 250 300 400 325 575 625 675

Sample Output 2

No

They violate the first condition because S_4 > S_5.


Sample Input 3

0 23 24 145 301 413 631 632

Sample Output 3

No

They violate the second and third conditions.

B - AtCoder Quiz 2

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

AtCoder 王国では、競技プログラミングの実力を測る検定試験が実施されています。

試験は 100 点満点であり、点数が高ければ高いほど、高いランクが認定されます。
ランクは以下のように定められています。

  • 0 点以上 40 点未満のとき、初級
  • 40 点以上 70 点未満のとき、中級
  • 70 点以上 90 点未満のとき、上級
  • 90 点以上のとき、エキスパート

高橋君は、この検定試験を受験し、X 点を取りました。

高橋君が認定されたランクより一つ高いランクとなるためには最低であと何点必要か求めてください。ただし、高橋君がエキスパートと認定された場合、それより高いランクは存在しないため expert と出力してください。

制約

  • 0 \leq X \leq 100
  • X は整数

入力

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

X

出力

答えを出力せよ。


入力例 1

56

出力例 1

14

高橋君は 56 点を取り、中級と認定されました。一つ高いランクである上級となるためには、最低であと 14 点必要です。


入力例 2

32

出力例 2

8

入力例 3

0

出力例 3

40

入力例 4

100

出力例 4

expert

高橋君は満点を取り、エキスパートと認定されました。これより高いランクは存在しないため、expert と出力します。

Score : 100 points

Problem Statement

In the Kingdom of AtCoder, there is a standardized test of competitive programming proficiency.

An examinee will get a score out of 100 and obtain a rank according to the score, as follows:

  • Novice, for a score not less than 0 but less than 40;
  • Intermediate, for a score not less than 40 but less than 70;
  • Advanced, for a score not less than 70 but less than 90;
  • Expert, for a score not less than 90.

Takahashi took this test and got X points.

Find the minimum number of extra points needed to go up one rank higher. If, however, his rank was Expert, print expert, as there is no higher rank than that.

Constraints

  • 0 \leq X \leq 100
  • X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the answer.


Sample Input 1

56

Sample Output 1

14

He got 56 points and was certified as Intermediate. In order to reach the next rank of Advanced, he needs at least 14 more points.


Sample Input 2

32

Sample Output 2

8

Sample Input 3

0

Sample Output 3

40

Sample Input 4

100

Sample Output 4

expert

He got full points and was certified as Expert. There is no rank higher than that, so print expert.

C - Intersection of Cuboids

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 250

問題文

あなたは3Dゲームの当たり判定を実装しようとしています。

3 次元空間内の直方体であって、2(a,b,c),(d,e,f) を結ぶ線分を対角線とし、全ての面が xy 平面、yz 平面、zx 平面のいずれかに平行なものを C(a,b,c,d,e,f) と表します。
(この定義により C(a,b,c,d,e,f) は一意に定まります)

2 つの直方体 C(a,b,c,d,e,f)C(g,h,i,j,k,l) が与えられるので、これらの共通部分の体積が正かどうか判定してください。

制約

  • 0 \leq a < d \leq 1000
  • 0 \leq b < e \leq 1000
  • 0 \leq c < f \leq 1000
  • 0 \leq g < j \leq 1000
  • 0 \leq h < k \leq 1000
  • 0 \leq i < l \leq 1000
  • 入力は全て整数

入力

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

a b c d e f
g h i j k l

出力

2 つの直方体の共通部分の体積が正なら Yes、そうでなければ No を出力せよ。


入力例 1

0 0 0 4 5 6
2 3 4 5 6 7

出力例 1

Yes

2 つの直方体の位置関係は下図のようになっており、共通部分の体積は 8 です。


入力例 2

0 0 0 2 2 2
0 0 2 2 2 4

出力例 2

No

2 つの直方体は面で接していますが、共通部分の体積は 0 です。


入力例 3

0 0 0 1000 1000 1000
10 10 10 100 100 100

出力例 3

Yes

Score : 250 points

Problem Statement

You are trying to implement collision detection in a 3D game.

In a 3-dimensional space, let C(a,b,c,d,e,f) denote the cuboid with a diagonal connecting (a,b,c) and (d,e,f), and with all faces parallel to the xy-plane, yz-plane, or zx-plane.
(This definition uniquely determines C(a,b,c,d,e,f).)

Given two cuboids C(a,b,c,d,e,f) and C(g,h,i,j,k,l), determine whether their intersection has a positive volume.

Constraints

  • 0 \leq a < d \leq 1000
  • 0 \leq b < e \leq 1000
  • 0 \leq c < f \leq 1000
  • 0 \leq g < j \leq 1000
  • 0 \leq h < k \leq 1000
  • 0 \leq i < l \leq 1000
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

a b c d e f
g h i j k l

Output

Print Yes if the intersection of the two cuboids has a positive volume, and No otherwise.


Sample Input 1

0 0 0 4 5 6
2 3 4 5 6 7

Sample Output 1

Yes

The positional relationship of the two cuboids is shown in the figure below, and their intersection has a volume of 8.


Sample Input 2

0 0 0 2 2 2
0 0 2 2 2 4

Sample Output 2

No

The two cuboids touch at a face, where the volume of the intersection is 0.


Sample Input 3

0 0 0 1000 1000 1000
10 10 10 100 100 100

Sample Output 3

Yes
D - Hands on Ring (Easy)

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 250

問題文

注:この問題は F 問題とほぼ同じ設定です。本文中で太字で示されている部分および制約のみが異なります。

あなたはあるリングを両手で握っています。 このリングは N\ (N\geq 3) 個のパーツ 1,2,\dots,N によって構成されており、パーツ i とパーツ i+1 (1\leq i\leq N-1)、およびパーツ 1 とパーツ N がそれぞれ隣接しています。

最初、左手はパーツ 1 を、右手はパーツ 2 を握っています。 あなたは、1 回の 操作 で以下のことを行えます。

  • 片方の手を、今握っているパーツに隣接するいずれかのパーツに移動する。ただし、移動先にもう一方の手がない場合に限る。

以下の図は、初期状態およびそこから行える操作と行えない操作の例を示したもので、リングの各パーツに書き込まれた数はそのパーツの番号を、L と書かれた丸は左手を、R と書かれた丸は右手を示しています。

あなたは今から与えられる Q 個の指示に順番に従う必要があります。 i\ (1\leq i\leq Q) 個目の指示は文字 H_i および整数 T_i によって表され、その意味は以下の通りです:

  • 操作を何回か(0 回でもよい)行うことで、H_iL ならば左手、R ならば右手が、パーツ T_i を握っている状態にする。 このとき、H_i によって指定された手ではない方の手を 動かしてはならない

なお、達成可能な指示しか与えられないことが保証されます。

詳細 この問題の設定の下では、各 i について、i 個目の指示に従う直前でのそれぞれの手の位置が一意に定まることが証明できます。 このとき、左手の位置をパーツ l_i、右手の位置をパーツ r_i とおくと、H_i= L ならば T_i\neq r_i が、H_i= R ならば T_i\neq l_i がそれぞれ保証されます。


すべての指示に従うために必要な操作回数の合計の最小値を求めてください。

制約

  • 3\leq N \leq 100
  • 1\leq Q \leq 100
  • H_iL または R
  • 1\leq T_i\leq N
  • N,Q,T_i は整数
  • 達成可能な指示しか与えられない(詳細は問題文を参照してください)

入力

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

N Q
H_1 T_1
H_2 T_2
\vdots
H_Q T_Q

出力

すべての指示に従うために必要な操作回数の合計の最小値を出力せよ。


入力例 1

6 3
R 4
L 5
R 6

出力例 1

8

以下のように操作を行うことで、Q 個の指示すべてに順番に従うことができます。

  1. 右手をパーツ 2\rightarrow 3\rightarrow 4 と移動させることで、1 番目の指示に従う。
  2. 左手をパーツ 1\rightarrow 6\rightarrow 5 と移動させることで、2 番目の指示に従う。
  3. 右手をパーツ 4\rightarrow 3\rightarrow 2\rightarrow 1\rightarrow 6 と移動させることで、3 番目の指示に従う。

このとき行う操作回数の合計は 2+2+4=8 であり、これが最小です。 (3 番目の指示に従う際に右手をパーツ 4\rightarrow 5\rightarrow 6 と移動させることはできないことに注意してください。)


入力例 2

100 2
L 1
R 2

出力例 2

0

操作を 1 度も行わずに指示に従うことができる場合もあります。


入力例 3

30 8
R 23
R 26
R 29
L 20
R 29
R 19
L 7
L 16

出力例 3

92

Score : 250 points

Problem Statement

Note: This problem has almost the same setting as Problem F. Only the parts in bold in the main text and constraints differ.

You are holding a ring with both hands. This ring consists of N\ (N \geq 3) parts numbered 1,2,\dots,N, where parts i and i+1 (1 \leq i \leq N-1) are adjacent, and parts 1 and N are also adjacent.

Initially, your left hand is holding part 1, and your right hand is holding part 2. In one operation, you can do the following:

  • Move one of your hands to an adjacent part of the part it is currently holding. However, you can do this only if the other hand is not on the destination part.

The following figure shows the initial state and examples of operations that can and cannot be made from there. The number written on each part of the ring represents the part number, and the circles labeled L and R represent your left and right hands, respectively.

You need to follow Q instructions given to you in order. The i-th (1 \leq i \leq Q) instruction is represented by a character H_i and an integer T_i, meaning the following:

  • Perform some number of operations (possibly zero) so that your left hand (if H_i is L) or your right hand (if H_i is R) is holding part T_i. Here, you must not move the other hand not specified by H_i.

It is guaranteed that only achievable instructions are given.

Details Under the settings of this problem, it can be proved that the positions of both hands are uniquely determined just before following the i-th instruction for each i. At that time, if we denote the positions of the left and right hands as parts l_i and r_i, respectively, it is guaranteed that T_i \neq r_i when H_i is L, and T_i \neq l_i when H_i is R.


Find the minimum total number of operations required to follow all the instructions.

Constraints

  • 3 \leq N \leq 100
  • 1 \leq Q \leq 100
  • H_i is L or R.
  • 1 \leq T_i \leq N
  • N, Q, and T_i are integers.
  • Only achievable instructions are given (see the problem statement for details).

Input

The Input is given from Standard Input in the following format:

N Q
H_1 T_1
H_2 T_2
\vdots
H_Q T_Q

Output

Print the minimum total number of operations required to follow all the instructions.


Sample Input 1

6 3
R 4
L 5
R 6

Sample Output 1

8

By performing the following operations, you can follow all Q instructions in order.

  1. Move your right hand as part 2 \rightarrow 3 \rightarrow 4 to follow the first instruction.
  2. Move your left hand as part 1 \rightarrow 6 \rightarrow 5 to follow the second instruction.
  3. Move your right hand as part 4 \rightarrow 3 \rightarrow 2 \rightarrow 1 \rightarrow 6 to follow the third instruction.

In this case, the total number of operations is 2+2+4=8, which is the minimum. (Note that when following the third instruction, you cannot move your right hand as part 4 \rightarrow 5 \rightarrow 6.)


Sample Input 2

100 2
L 1
R 2

Sample Output 2

0

There are cases where you can follow the instructions without performing any operations.


Sample Input 3

30 8
R 23
R 26
R 29
L 20
R 29
R 19
L 7
L 16

Sample Output 3

92
E - Dice Sum

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

長さ N の整数からなる数列 A=(A_1,\ldots,A_N) であって、以下の条件を全て満たすものは何通りありますか?

  • 1\le A_i \le M (1 \le i \le N)

  • \displaystyle\sum _{i=1}^N A_i \leq K

ただし、答えは非常に大きくなることがあるので、答えを 998244353 で割った余りを求めてください。

制約

  • 1 \leq N, M \leq 50
  • N \leq K \leq NM
  • 入力は全て整数

入力

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

N M K

出力

答えを 998244353 で割った余りを出力せよ。


入力例 1

2 3 4

出力例 1

6

条件を満たす数列は以下の 6 つです。

  • (1,1)
  • (1,2)
  • (1,3)
  • (2,1)
  • (2,2)
  • (3,1)

入力例 2

31 41 592

出力例 2

798416518

答えを 998244353 で割った余りを出力してください。

Score : 300 points

Problem Statement

How many integer sequences of length N, A=(A_1, \ldots, A_N), satisfy all of the conditions below?

  • 1\le A_i \le M (1 \le i \le N)

  • \displaystyle\sum _{i=1}^N A_i \leq K

Since the count can get enormous, find it modulo 998244353.

Constraints

  • 1 \leq N, M \leq 50
  • N \leq K \leq NM
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K

Output

Print the answer.


Sample Input 1

2 3 4

Sample Output 1

6

The following six sequences satisfy the conditions.

  • (1,1)
  • (1,2)
  • (1,3)
  • (2,1)
  • (2,2)
  • (3,1)

Sample Input 2

31 41 592

Sample Output 2

798416518

Be sure to print the count modulo 998244353.