A - Signed Difficulty

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

実数 X.Y が与えられます。ただし Y はちょうど 1 桁です。

  • 0 \leq Y \leq 2 ならば、X-
  • 3 \leq Y \leq 6 ならば、X
  • 7 \leq Y \leq 9 ならば、X+

と出力してください。

制約

  • 1 \leq X \leq 15
  • 0 \leq Y \leq 9
  • XY は整数

入力

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

X.Y

出力

答えを出力せよ。


入力例 1

15.8

出力例 1

15+

15 + のような出力は不正解とみなされます。
X+ の間や、X- の間には空白を入れずに出力してください。


入力例 2

1.0

出力例 2

1-

1.001 などの値が入力として与えられることはありません。


入力例 3

12.5

出力例 3

12

Score : 100 points

Problem Statement

You are given a real number X.Y, where Y is a single digit.

Print the following: (quotes for clarity)

  • X-, if 0 \leq Y \leq 2;
  • X, if 3 \leq Y \leq 6;
  • X+, if 7 \leq Y \leq 9.

Constraints

  • 1 \leq X \leq 15
  • 0 \leq Y \leq 9
  • X and Y are integers.

Input

Input is given from Standard Input in the following format:

X.Y

Output

Print the answer.


Sample Input 1

15.8

Sample Output 1

15+

Here, printing 15 + will not be accepted: do not print a space between X and +, or between X and -.


Sample Input 2

1.0

Sample Output 2

1-

You will not get inputs such as 1.00 and 1.


Sample Input 3

12.5

Sample Output 3

12
B - Edge Checker 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

下の画像で示す図において、a 番の点と b 番の点が線で直接結ばれているかを答えてください。

制約

  • 1 \leq a \lt b \leq 15
  • a,b は整数

入力

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

a b

出力

a 番の点と b 番の点が線で直接結ばれているなら Yes、結ばれていないなら No を出力せよ。


入力例 1

1 2

出力例 1

Yes

問題文で示した図において、1 番の点と 2 番の点は線で直接結ばれています。 よって、Yes を出力します。


入力例 2

2 8

出力例 2

No

問題文で示した図において、2 番の点と 8 番の点は線で直接結ばれていません。 よって、No を出力します。


入力例 3

14 15

出力例 3

No

Score : 100 points

Problem Statement

Determine if there is a segment that directly connects the points numbered a and b in the figure below.

Constraints

  • 1 \leq a \lt b \leq 15
  • a and b are integers.

Input

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

a b

Output

Print Yes if there is a segment that directly connects the points numbered a and b; print No otherwise.


Sample Input 1

1 2

Sample Output 1

Yes

In the figure in the Problem Statement, there is a segment that directly connects the points numbered 1 and 2, so Yes should be printed.


Sample Input 2

2 8

Sample Output 2

No

In the figure in the Problem Statement, there is no segment that directly connects the points numbered 2 and 8, so No should be printed.


Sample Input 3

14 15

Sample Output 3

No
C - Overlapping sheets

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

座標平面上に N 枚の長方形のシートが張られています。

各シートが覆う長方形領域の各辺はそれぞれ x 軸または y 軸と平行であり、
具体的には、i 枚目のシートはちょうど A_i \leq x\leq B_i かつ C_i \leq y\leq D_i をみたす領域全体を覆っています。

1 枚以上のシートによって覆われている領域 の面積を S とすると、 S は制約の条件下で整数となる事が証明できます。
S を整数の形で出力してください。

制約

  • 2\leq N\leq 100
  • 0\leq A_i<B_i\leq 100
  • 0\leq C_i<D_i\leq 100
  • 入力はすべて整数

入力

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

N
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
\vdots
A_N B_N C_N D_N

出力

1 枚以上のシートによって覆われている領域の面積 S を整数で出力せよ。


入力例 1

3
0 5 1 3
1 4 0 5
2 5 2 4

出力例 1

20

3 枚のシートによって覆われている領域は次のようになります。
ここで、赤色・黄色・青色はそれぞれ 1 枚目・ 2 枚目・ 3 枚目のシートによって覆われている領域を表しています。

よって、1 枚以上のシートによって覆われている領域の面積は S=20 となります。


入力例 2

2
0 100 0 100
0 100 0 100

出力例 2

10000

異なるシートが同じ領域を覆っている事があることに注意してください。


入力例 3

3
0 1 0 1
0 3 0 5
5 10 0 10

出力例 3

65

Score : 200 points

Problem Statement

There are N rectangular sheets spread out on a coordinate plane.

Each side of the rectangular region covered by each sheet is parallel to the x- or y-axis.
Specifically, the i-th sheet covers exactly the region satisfying A_i \leq x\leq B_i and C_i \leq y\leq D_i.

Let S be the area of the region covered by one or more sheets. It can be proved that S is an integer under the constraints.
Print S as an integer.

Constraints

  • 2\leq N\leq 100
  • 0\leq A_i<B_i\leq 100
  • 0\leq C_i<D_i\leq 100
  • All input values are integers.

Input

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

N
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
\vdots
A_N B_N C_N D_N

Output

Print the area S of the region covered by one or more sheets as an integer.


Sample Input 1

3
0 5 1 3
1 4 0 5
2 5 2 4

Sample Output 1

20

The three sheets cover the following regions.
Here, red, yellow, and blue represent the regions covered by the first, second, and third sheets, respectively.

Therefore, the area of the region covered by one or more sheets is S=20.


Sample Input 2

2
0 100 0 100
0 100 0 100

Sample Output 2

10000

Note that different sheets may cover the same region.


Sample Input 3

3
0 1 0 1
0 3 0 5
5 10 0 10

Sample Output 3

65
D - AtCoder Quiz

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

AtCoder では現在、 ABC , ARC , AGC , AHC4 つのコンテストが定期的に開催されています。

AtCoder で現在定期的に開催されているコンテストは S_1 , S_2 , S_3 とあと 1 つは何ですか?

制約

  • S_1 , S_2 , S_3 はそれぞれ、 ABC , ARC , AGC , AHC のいずれかである。
  • S_1 , S_2 , S_3 は相異なる。

入力

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

S_1
S_2
S_3

出力

答えを出力せよ。


入力例 1

ARC
AGC
AHC

出力例 1

ABC

ARC , AGC , AHC3つが入力として与えられているので、 残りの 1 つはABC です。


入力例 2

AGC
ABC
ARC

出力例 2

AHC

Score : 200 points

Problem Statement

AtCoder currently holds four series of regular contests: ABC, ARC, AGC, and AHC.

What is the series of regular contests currently held by AtCoder in addition to S_1, S_2, and S_3?

Constraints

  • Each of S_1, S_2, and S_3 is ABC, ARC, AGC, or AHC.
  • S_1, S_2, and S_3 are pairwise different.

Input

Input is given from Standard Input in the following format:

S_1
S_2
S_3

Output

Print the answer.


Sample Input 1

ARC
AGC
AHC

Sample Output 1

ABC

Given in input are ARC, AGC, and AHC. The rest is ABC.


Sample Input 2

AGC
ABC
ARC

Sample Output 2

AHC
E - Bib

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

1 から N の番号がついた N 人の人がいます。

i は数 Q_i が書かれたゼッケンを着けており、人 P_i を見つめています。

i が書かれたゼッケンを着けている人が見つめている人の着けているゼッケンにかかれている数を、i=1,2,\ldots,N のそれぞれについて求めてください。

制約

  • 2 \leq N \leq 3\times 10^5
  • 1 \leq P_i \leq N
  • P_i は相異なる
  • 1 \leq Q_i \leq N
  • Q_i は相異なる
  • 入力は全て整数である

入力

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

N
P_1 P_2 \dots P_N
Q_1 Q_2 \dots Q_N

出力

i が書かれたゼッケンを着けている人が見つめている人の着けているゼッケンにかかれている数を S_i とする。
S_1,S_2,\ldots,S_N をこの順に空白区切りで出力せよ。


入力例 1

4
4 3 2 1
2 3 1 4

出力例 1

3 4 1 2

31 が書かれたゼッケンを着けており、人 3 が見つめている人 23 が書かれたゼッケンを着けています。 よって i=1 に対する答えは 3 になります。

図


入力例 2

10
2 6 4 3 7 8 9 10 1 5
1 4 8 2 10 5 7 3 9 6

出力例 2

4 8 6 5 3 10 9 2 1 7

Score : 300 points

Problem Statement

There are N people numbered from 1 to N.

Person i is wearing a bib with the number Q_i and is staring at person P_i.

For each i = 1,2,\ldots,N, find the number written on the bib of the person that the person wearing the bib with number i is staring at.

Constraints

  • 2 \leq N \leq 3\times 10^5
  • 1 \leq P_i \leq N
  • The values of P_i are distinct.
  • 1 \leq Q_i \leq N
  • The values of Q_i are distinct.
  • All input values are integers.

Input

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

N
P_1 P_2 \dots P_N
Q_1 Q_2 \dots Q_N

Output

Let S_i be the number written on the bib of the person that the person wearing the bib with number i is staring at.
Print S_1, S_2, \ldots, S_N in this order, separated by a single space.


Sample Input 1

4
4 3 2 1
2 3 1 4

Sample Output 1

3 4 1 2

Person 3 is wearing the bib with the number 1, and the person that person 3 is staring at, person 2, is wearing the bib with the number 3. Thus, the answer for i = 1 is 3.

Figure


Sample Input 2

10
2 6 4 3 7 8 9 10 1 5
1 4 8 2 10 5 7 3 9 6

Sample Output 2

4 8 6 5 3 10 9 2 1 7
F - Ladder Takahashi

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

10^9 階建てのビルがあり、N 本のはしごがかかっています。
ビルの 1 階にいる高橋君ははしごを繰り返し使って(0 回でもよい)できるだけ高い階へ上りたいと考えています。
はしごには 1 から N までの番号がついており、はしご iA_i 階と B_i 階を結んでいます。はしご i を利用すると A_i 階から B_i 階へ、または B_i 階から A_i 階へ双方向に移動することができますが、それ以外の階の間の移動は行うことはできません。
また、高橋君は同じ階での移動は自由に行うことができますが、はしご以外の方法で他の階へ移動することはできません。
高橋君は最高で何階へ上ることができますか?

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq A_i, B_i \leq 10^9
  • A_i \neq B_i
  • 入力はすべて整数

入力

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

N
A_1 B_1
A_2 B_2
\ldots
A_N B_N

出力

答えを出力せよ。


入力例 1

4
1 4
4 3
4 10
8 3

出力例 1

10

はしご 14 階に進み、はしご 310 階に進むことにより、10 階にたどり着くことができます。


入力例 2

6
1 3
1 5
1 12
3 5
3 12
5 12

出力例 2

12

入力例 3

3
500000000 600000000
600000000 700000000
700000000 800000000

出力例 3

1

他の階への移動ができない場合もあります。

Score : 300 points

Problem Statement

There is a 10^9-story building with N ladders.
Takahashi, who is on the 1-st (lowest) floor, wants to reach the highest floor possible by using ladders (possibly none).
The ladders are numbered from 1 to N, and ladder i connects the A_i-th and B_i-th floors. One can use ladder i in either direction to move from the A_i-th floor to the B_i-th floor or vice versa, but not between other floors.
Takahashi can freely move within the same floor, but cannot move between floors without using ladders.
What is the highest floor Takahashi can reach?

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq A_i, B_i \leq 10^9
  • A_i \neq B_i
  • All values in the input are integers.

Input

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

N
A_1 B_1
A_2 B_2
\ldots
A_N B_N

Output

Print an integer representing the answer.


Sample Input 1

4
1 4
4 3
4 10
8 3

Sample Output 1

10

He can reach the 10-th floor by using ladder 1 to get to the 4-th floor and then ladder 3 to get to the 10-th floor.


Sample Input 2

6
1 3
1 5
1 12
3 5
3 12
5 12

Sample Output 2

12

Sample Input 3

3
500000000 600000000
600000000 700000000
700000000 800000000

Sample Output 3

1

He may be unable to move between floors.

G - Repeated Sequence

Time Limit: 2 sec / Memory Limit: 1024 MiB



配点 : 400

問題文

周期 N をもつ無限数列 A=(A _ 1,A _ 2,A _ 3,\dotsc) の先頭 NA _ 1,A _ 2,\dotsc,A _ N が与えられます。

この数列の空でない連続する部分列のうち、和が S となるものが存在するか判定してください。

ただし、無限数列 A が周期 N をもつとは、i\gt N を満たすすべての整数 i に対して A _ i=A _ {i-N} が成り立つことをいいます。

制約

  • 1\leq N\leq2\times10 ^ 5
  • 1\leq A _ i\leq 10 ^ 9
  • 1\leq S\leq 10 ^ {18}
  • 入力はすべて整数

入力

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

N S
A _ 1 A _ 2 \dotsc A _ N

出力

A の連続する部分列 (A _ l,A _ {l+1},\dotsc,A _ r) であって、A _ l+A _ {l+1}+\dotsb+A _ r=S となるものが存在するならば Yes を、そうでないならば No を出力せよ。


入力例 1

3 42
3 8 4

出力例 1

Yes

数列 A(3,8,4,3,8,4,3,8,4,\dotsc) のようになります。

A の部分列 (A _ 2,A _ 3,A _ 4,A _ 5,A _ 6,A _ 7,A _ 8,A _ 9)=(8,4,3,8,4,3,8,4) について 8+4+3+8+4+3+8+4=42 が成り立つので、Yes を出力してください。


入力例 2

3 1
3 8 4

出力例 2

No

A の要素はすべて 3 以上なので、A の空でない連続する部分列の総和は 3 以上です。

よって、総和が 1 となるような部分列は存在しないため、No を出力してください。


入力例 3

20 83298426
748 169 586 329 972 529 432 519 408 587 138 249 656 114 632 299 984 755 404 772

出力例 3

Yes

入力例 4

20 85415869
748 169 586 329 972 529 432 519 408 587 138 249 656 114 632 299 984 755 404 772

出力例 4

No

Score : 400 points

Problem Statement

You are given the first N terms A _ 1,A _ 2,\dotsc,A _ N of an infinite sequence A=(A _ 1,A _ 2,A _ 3,\dotsc) that has period N.

Determine if there exists a non-empty contiguous subsequence of this infinite sequence whose sum is S.

Here, an infinite sequence A has period N when A _ i=A _ {i-N} for every integer i>N.

Constraints

  • 1\leq N\leq2\times10 ^ 5
  • 1\leq A _ i\leq 10 ^ 9
  • 1\leq S\leq 10 ^ {18}
  • All input values are integers.

Input

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

N S
A _ 1 A _ 2 \dotsc A _ N

Output

If there exists a contiguous subsequence (A _ l,A _ {l+1},\dotsc,A _ r) of A for which A _ l+A _ {l+1}+\dotsb+A _ r=S, print Yes. Otherwise, print No.


Sample Input 1

3 42
3 8 4

Sample Output 1

Yes

The sequence A is (3,8,4,3,8,4,3,8,4,\dotsc).

For the subsequence (A _ 2,A _ 3,A _ 4,A _ 5,A _ 6,A _ 7,A _ 8,A _ 9)=(8,4,3,8,4,3,8,4), we have 8+4+3+8+4+3+8+4=42, so print Yes.


Sample Input 2

3 1
3 8 4

Sample Output 2

No

All elements of A are at least 3, so the sum of any non-empty contiguous subsequence is at least 3.

Thus, there is no subsequence with sum 1, so print No.


Sample Input 3

20 83298426
748 169 586 329 972 529 432 519 408 587 138 249 656 114 632 299 984 755 404 772

Sample Output 3

Yes

Sample Input 4

20 85415869
748 169 586 329 972 529 432 519 408 587 138 249 656 114 632 299 984 755 404 772

Sample Output 4

No
H - Best Performances

Time Limit: 6 sec / Memory Limit: 1024 MiB

配点 : 475

問題文

長さ N の数列 A=(A_1,A_2,\dots,A_N) があり、最初全ての項が 0 です。
入力で与えられる整数 K を用いて関数 f(A) を以下のように定義します。

  • A を降順に (広義単調減少となるように) ソートしたものを B とする。
  • このとき、 f(A)=B_1 + B_2 + \dots + B_K とする。

この数列に合計 Q 回の更新を行うことを考えます。
数列 A に対し以下の更新を i=1,2,\dots,Q の順に行い、各更新ごとにその時点での f(A) の値を出力してください。

  • A_{X_i}Y_i に変更する。

制約

  • 入力は全て整数
  • 1 \le K \le N \le 5 \times 10^5
  • 1 \le Q \le 5 \times 10^5
  • 1 \le X_i \le N
  • 0 \le Y_i \le 10^9

入力

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

N K Q
X_1 Y_1
X_2 Y_2
\vdots
X_Q Y_Q

出力

全体で Q 行出力せよ。そのうち i 行目には i 回目の更新を終えた時点での f(A) の値を整数として出力せよ。


入力例 1

4 2 10
1 5
2 1
3 3
4 2
2 10
1 0
4 0
3 1
2 0
3 0

出力例 1

5
6
8
8
15
13
13
11
1
0

この入力では N=4,K=2 です。 Q=10 回の更新を行います。

  • 1 回目の更新を受けて A=(5,0,0,0) となります。このとき f(A)=5 です。
  • 2 回目の更新を受けて A=(5,1,0,0) となります。このとき f(A)=6 です。
  • 3 回目の更新を受けて A=(5,1,3,0) となります。このとき f(A)=8 です。
  • 4 回目の更新を受けて A=(5,1,3,2) となります。このとき f(A)=8 です。
  • 5 回目の更新を受けて A=(5,10,3,2) となります。このとき f(A)=15 です。
  • 6 回目の更新を受けて A=(0,10,3,2) となります。このとき f(A)=13 です。
  • 7 回目の更新を受けて A=(0,10,3,0) となります。このとき f(A)=13 です。
  • 8 回目の更新を受けて A=(0,10,1,0) となります。このとき f(A)=11 です。
  • 9 回目の更新を受けて A=(0,0,1,0) となります。このとき f(A)=1 です。
  • 10 回目の更新を受けて A=(0,0,0,0) となります。このとき f(A)=0 です。

Score : 475 points

Problem Statement

We have a sequence A=(A_1,A_2,\dots,A_N) of length N. Initially, all the terms are 0.
Using an integer K given in the input, we define a function f(A) as follows:

  • Let B be the sequence obtained by sorting A in descending order (so that it becomes monotonically non-increasing).
  • Then, let f(A)=B_1 + B_2 + \dots + B_K.

We consider applying Q updates on this sequence.
Apply the following operation on the sequence A for i=1,2,\dots,Q in this order, and print the value f(A) at that point after each update.

  • Change A_{X_i} to Y_i.

Constraints

  • All input values are integers.
  • 1 \le K \le N \le 5 \times 10^5
  • 1 \le Q \le 5 \times 10^5
  • 1 \le X_i \le N
  • 0 \le Y_i \le 10^9

Input

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

N K Q
X_1 Y_1
X_2 Y_2
\vdots
X_Q Y_Q

Output

Print Q lines in total. The i-th line should contain the value f(A) as an integer when the i-th update has ended.


Sample Input 1

4 2 10
1 5
2 1
3 3
4 2
2 10
1 0
4 0
3 1
2 0
3 0

Sample Output 1

5
6
8
8
15
13
13
11
1
0

In this input, N=4 and K=2. Q=10 updates are applied.

  • The 1-st update makes A=(5, 0,0,0). Now, f(A)=5.
  • The 2-nd update makes A=(5, 1,0,0). Now, f(A)=6.
  • The 3-rd update makes A=(5, 1,3,0). Now, f(A)=8.
  • The 4-th update makes A=(5, 1,3,2). Now, f(A)=8.
  • The 5-th update makes A=(5,10,3,2). Now, f(A)=15.
  • The 6-th update makes A=(0,10,3,2). Now, f(A)=13.
  • The 7-th update makes A=(0,10,3,0). Now, f(A)=13.
  • The 8-th update makes A=(0,10,1,0). Now, f(A)=11.
  • The 9-th update makes A=(0, 0,1,0). Now, f(A)=1.
  • The 10-th update makes A=(0, 0,0,0). Now, f(A)=0.
I - Teleporting Takahashi 2

Time Limit: 3 sec / Memory Limit: 1024 MiB

配点 : 525

問題文

N 頂点 N+M 辺の単純有向グラフ G があります。頂点には 1 から N の番号が、辺には 1 から N+M までの番号がつけられています。

i (1 \leq i \leq N) は頂点 i から頂点 i+1 へ張られています。(ただし、頂点 N+1 は頂点 1 とみなします。)
N+i\ (1\leq i\leq M) は頂点 X_i から頂点 Y_i へ張られています。

高橋君は頂点 1 にいます。各頂点において、高橋君はその頂点から有向辺が張られている頂点に移動することができます。

高橋君がちょうど K 回移動する方法が何通りあるかを求めてください。

すなわち、長さ K+1 の 整数列 (v_0,v_1,\dots,v_K) であって、下記の 3 つの条件をすべて満たすものの個数を求めてください。

  • i=0,1,\dots,K について、1\leq v_i\leq N
  • v_0=1
  • i=1,2,\ldots,K について、頂点 v_{i-1} から頂点 v_i へ有向辺が張られている。

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

制約

  • 2\leq N\leq 2\times 10^5
  • 0\leq M\leq 50
  • 1\leq K\leq 2\times 10^5
  • 1\leq X_i,Y_i\leq N,X_i\neq Y_i
  • N+M 本の有向辺はすべて異なる
  • 入力は全て整数

入力

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

N M K
X_1 Y_1
X_2 Y_2
\vdots
X_M Y_M

出力

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


入力例 1

6 2 5
1 4
2 5

出力例 1

5

sample1

上図はグラフ G を表しています。以下の 5 通りの移動方法が存在します。

  • 頂点 1\to 頂点 2\to 頂点 3\to 頂点 4\to 頂点 5\to 頂点 6
  • 頂点 1\to 頂点 2\to 頂点 5\to 頂点 6\to 頂点 1\to 頂点 2
  • 頂点 1\to 頂点 2\to 頂点 5\to 頂点 6\to 頂点 1\to 頂点 4
  • 頂点 1\to 頂点 4\to 頂点 5\to 頂点 6\to 頂点 1\to 頂点 2
  • 頂点 1\to 頂点 4\to 頂点 5\to 頂点 6\to 頂点 1\to 頂点 4

入力例 2

10 0 200000

出力例 2

1

入力例 3

199 10 1326
122 39
142 49
164 119
197 127
188 145
69 80
6 120
24 160
18 154
185 27

出力例 3

451022766

Score : 525 points

Problem Statement

There is a simple directed graph G with N vertices and N+M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to N+M.

Edge i (1 \leq i \leq N) goes from vertex i to vertex i+1. (Here, vertex N+1 is considered as vertex 1.)
Edge N+i (1 \leq i \leq M) goes from vertex X_i to vertex Y_i.

Takahashi is at vertex 1. At each vertex, he can move to any vertex to which there is an outgoing edge from the current vertex.

Compute the number of ways he can move exactly K times.

That is, find the number of integer sequences (v_0, v_1, \dots, v_K) of length K+1 satisfying all of the following three conditions:

  • 1 \leq v_i \leq N for i = 0, 1, \dots, K.
  • v_0 = 1.
  • There is a directed edge from vertex v_{i-1} to vertex v_i for i = 1, 2, \ldots, K.

Since this number can be very large, print it modulo 998244353.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq 50
  • 1 \leq K \leq 2 \times 10^5
  • 1 \leq X_i, Y_i \leq N, X_i \neq Y_i
  • All of the N+M directed edges are distinct.
  • All input values are integers.

Input

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

N M K
X_1 Y_1
X_2 Y_2
\vdots
X_M Y_M

Output

Print the count modulo 998244353.


Sample Input 1

6 2 5
1 4
2 5

Sample Output 1

5

sample1

The above figure represents the graph G. There are five ways for Takahashi to move:

  • Vertex 1 \to Vertex 2 \to Vertex 3 \to Vertex 4 \to Vertex 5 \to Vertex 6
  • Vertex 1 \to Vertex 2 \to Vertex 5 \to Vertex 6 \to Vertex 1 \to Vertex 2
  • Vertex 1 \to Vertex 2 \to Vertex 5 \to Vertex 6 \to Vertex 1 \to Vertex 4
  • Vertex 1 \to Vertex 4 \to Vertex 5 \to Vertex 6 \to Vertex 1 \to Vertex 2
  • Vertex 1 \to Vertex 4 \to Vertex 5 \to Vertex 6 \to Vertex 1 \to Vertex 4

Sample Input 2

10 0 200000

Sample Output 2

1

Sample Input 3

199 10 1326
122 39
142 49
164 119
197 127
188 145
69 80
6 120
24 160
18 154
185 27

Sample Output 3

451022766