A - Good morning

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

配点 : 100

問題文

ある日、高橋君は AB 分ちょうどに、青木君は CD1 秒に起きました。
高橋君の起床時刻が青木君より早いならば Takahashi を、そうでないならば Aoki を出力してください。

制約

  • 0 \leq A \leq 23
  • 0 \leq B \leq 59
  • 0 \leq C \leq 23
  • 0 \leq D \leq 59
  • 入力はすべて整数である。

入力

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

A B C D

出力

高橋君の起床時刻が青木君より早いならば Takahashi を、そうでないならば Aoki を出力せよ。


入力例 1

7 0 6 30

出力例 1

Aoki

高橋君は 7 時ちょうどに、青木君は 6301 秒に起きました。 青木君の起床時刻の方が早いため、Aoki を出力します。


入力例 2

7 30 7 30

出力例 2

Takahashi

高橋君は 730 分ちょうどに、青木君は 7301 秒に起きました。 高橋君の起床時刻の方が 1 秒だけ早いため、Takahashi を出力します。


入力例 3

0 0 23 59

出力例 3

Takahashi

ある日の 00 分ちょうどはその日の 01 分の 1 分前であり、 その日の 2359 分の 1 分後、すなわちいわゆる 24 時ちょうどのことではありません。 よって、高橋君の起床時刻の方が早く、Takahashi を出力します。

Score : 100 points

Problem Statement

One day, Takahashi got up at exactly B minutes past A o'clock (in 24-hour clock), and Aoki got up at exactly D minutes and 1 second past C o'clock.
If Takahashi got up earlier than Aoki, print Takahashi; otherwise, print Aoki.

Constraints

  • 0 \leq A \leq 23
  • 0 \leq B \leq 59
  • 0 \leq C \leq 23
  • 0 \leq D \leq 59
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

If Takahashi got up earlier than Aoki, print Takahashi; otherwise, print Aoki.


Sample Input 1

7 0 6 30

Sample Output 1

Aoki

Takahashi got up at 7 sharp, and Aoki got up at 30 minutes and 1 second past 6 o'clock. Aoki was the first to get up, so Aoki should be printed.


Sample Input 2

7 30 7 30

Sample Output 2

Takahashi

Takahashi got up at exactly half past 7, and Aoki got up at 30 minutes and 1 second past 7 o'clock. Just by one second, Takahashi was the first to get up, so Takahashi should be printed.


Sample Input 3

0 0 23 59

Sample Output 3

Takahashi

0:00 in a day is one minute before 0:01, not one minute past 23:59 ("24:00"). Thus, Takahashi was the first to get up, so Takahashi should be printed.

B - Mex

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

配点 : 200

問題文

長さ N の整数からなる数列 A=(A_1,\ldots,A_N) が与えられます。

A_1,\ldots,A_N に含まれない最小の非負整数を求めてください。

制約

  • 1 \leq N \leq 2000
  • 0 \leq A_i \leq 2000
  • 入力は全て整数である

入力

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

N
A_1 \ldots A_N

出力

答えを出力せよ。


入力例 1

8
0 3 2 6 2 1 0 0

出力例 1

4

非負整数は 0,1,2,3,4,\ldots と続きます。
0,1,2,3A に含まれ、4A に含まれないので、答えは 4 です。


入力例 2

3
2000 2000 2000

出力例 2

0

Score : 200 points

Problem Statement

You are given a sequence of length N consisting of integers: A=(A_1,\ldots,A_N).

Find the smallest non-negative integer not in (A_1,\ldots,A_N).

Constraints

  • 1 \leq N \leq 2000
  • 0 \leq A_i \leq 2000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

Print the answer.


Sample Input 1

8
0 3 2 6 2 1 0 0

Sample Output 1

4

The non-negative integers are 0,1,2,3,4,\ldots.
We have 0,1,2,3 in A, but not 4, so the answer is 4.


Sample Input 2

3
2000 2000 2000

Sample Output 2

0
C - Choose Elements

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

配点 : 300

問題文

長さ N の整数からなる数列 A=(A_1,\ldots,A_N),B=(B_1,\ldots,B_N) が与えられます。

以下の条件を全て満たす長さ N の数列 X=(X_1,\ldots,X_N) が存在するかを判定してください。

  • すべての i(1\leq i\leq N) について、X_i = A_i または X_i = B_i

  • すべての i(1\leq i\leq N-1) について、|X_i - X_{i+1}| \leq K

制約

  • 1 \leq N \leq 2\times 10^5
  • 0 \leq K \leq 10^9
  • 1 \leq A_i,B_i \leq 10^9
  • 入力は全て整数である

入力

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

N K
A_1 \ldots A_N
B_1 \ldots B_N

出力

条件を全て満たす X が存在するならば Yes と、存在しないならば No と出力せよ。


入力例 1

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

出力例 1

Yes

X=(9,6,3,7,5) が全ての条件を満たします。


入力例 2

4 90
1 1 1 100
1 2 3 100

出力例 2

No

条件を満たす X は存在しません。


入力例 3

4 1000000000
1 1 1000000000 1000000000
1 1000000000 1 1000000000

出力例 3

Yes

Score : 300 points

Problem Statement

You are given two sequences, each of length N, consisting of integers: A=(A_1, \ldots, A_N) and B=(B_1, \ldots, B_N).

Determine whether there is a sequence of length N, X=(X_1, \ldots, X_N), satisfying all of the conditions below.

  • X_i = A_i or X_i = B_i, for every i(1\leq i\leq N).

  • |X_i - X_{i+1}| \leq K, for every i(1\leq i\leq N-1).

Constraints

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

Input

Input is given from Standard Input in the following format:

N K
A_1 \ldots A_N
B_1 \ldots B_N

Output

If there is an X that satisfies all of the conditions, print Yes; otherwise, print No.


Sample Input 1

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

Sample Output 1

Yes

X=(9,6,3,7,5) satisfies all conditions.


Sample Input 2

4 90
1 1 1 100
1 2 3 100

Sample Output 2

No

No X satisfies all conditions.


Sample Input 3

4 1000000000
1 1 1000000000 1000000000
1 1000000000 1 1000000000

Sample Output 3

Yes
D - Polynomial division

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

配点 : 400

問題文

N 次多項式 A(x)=A_Nx^N+A_{N-1}x^{N-1}+\cdots +A_1x+A_0
M 次多項式 B(x)=B_Mx^M+B_{M-1}x^{M-1}+\cdots +B_1x+B_0 があります。
ここで、A(x), B(x) の各係数は絶対値が 100 以下の整数であり、最高次の係数は 0 ではありません。

また、それらの積を C(x)=A(x)B(x)=C_{N+M}x^{N+M}+C_{N+M-1}x^{N+M-1}+\cdots +C_1x+C_0 とします。

A_0,A_1,\ldots, A_N および C_0,C_1,\ldots, C_{N+M} が与えられるので、B_0,B_1,\ldots, B_M を求めてください。
ただし、与えられる入力に対して、条件をみたす B_0,B_1,\ldots, B_M がただ一つ存在することが保証されます。

制約

  • 1 \leq N < 100
  • 1 \leq M < 100
  • |A_i| \leq 100
  • |C_i| \leq 10^6
  • A_N \neq 0
  • C_{N+M} \neq 0
  • 条件をみたす B_0,B_1,\ldots, B_M がただ一つ存在する。

入力

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

N M
A_0 A_1 \ldots A_{N-1} A_N
C_0 C_1 \ldots C_{N+M-1} C_{N+M}

出力

M+1 個の整数 B_0,B_1,\ldots, B_M を空白区切りで一行に出力せよ。


入力例 1

1 2
2 1
12 14 8 2

出力例 1

6 4 2

A(x)=x+2, B(x)=2x^2+4x+6 のとき、C(x)=A(x)B(x)=(x+2)(2x^2+4x+6)=2x^3+8x^2+14x+12 であるので、 B(x)=2x^2+4x+6 が条件をみたします。 よって、B_0=6, B_1=4, B_2=2 をこの順に空白区切りで出力します。


入力例 2

1 1
100 1
10000 0 -1

出力例 2

100 -1

A(x)=x+100, C(x)=-x^2+10000 であり、B(x)=-x+100 が条件をみたします。 よって、100, -1 をこの順に空白区切りで出力します。

Score : 400 points

Problem Statement

We have a polynomial of degree N, A(x)=A_Nx^N+A_{N-1}x^{N-1}+\cdots +A_1x+A_0,
and another of degree M, B(x)=B_Mx^M+B_{M-1}x^{M-1}+\cdots +B_1x+B_0.
Here, each coefficient of A(x) and B(x) is an integer whose absolute value is at most 100, and the leading coefficients are not 0.

Also, let the product of them be C(x)=A(x)B(x)=C_{N+M}x^{N+M}+C_{N+M-1}x^{N+M-1}+\cdots +C_1x+C_0.

Given A_0,A_1,\ldots, A_N and C_0,C_1,\ldots, C_{N+M}, find B_0,B_1,\ldots, B_M.
Here, the given inputs guarantee that there is a unique sequence B_0, B_1, \ldots, B_M that satisfies the given conditions.

Constraints

  • 1 \leq N < 100
  • 1 \leq M < 100
  • |A_i| \leq 100
  • |C_i| \leq 10^6
  • A_N \neq 0
  • C_{N+M} \neq 0
  • There is a unique sequence B_0, B_1, \ldots, B_M that satisfies the conditions given in the statement.

Input

Input is given from Standard Input in the following format:

N M
A_0 A_1 \ldots A_{N-1} A_N
C_0 C_1 \ldots C_{N+M-1} C_{N+M}

Output

Print the M+1 integers B_0,B_1,\ldots, B_M in one line, with spaces in between.


Sample Input 1

1 2
2 1
12 14 8 2

Sample Output 1

6 4 2

For A(x)=x+2 and B(x)=2x^2+4x+6, we have C(x)=A(x)B(x)=(x+2)(2x^2+4x+6)=2x^3+8x^2+14x+12, so B(x)=2x^2+4x+6 satisfies the given conditions. Thus, B_0=6, B_1=4, B_2=2 should be printed in this order, with spaces in between.


Sample Input 2

1 1
100 1
10000 0 -1

Sample Output 2

100 -1

We have A(x)=x+100, C(x)=-x^2+10000, for which B(x)=-x+100 satisfies the given conditions. Thus, 100, -1 should be printed in this order, with spaces in between.

E - Wrapping Chocolate

実行時間制限: 4 sec / メモリ制限: 1024 MB

配点 : 500

問題文

高橋君は N 枚のチョコレートを持っています。i 枚目のチョコレートは縦 A_i cm 横 B_i cm の長方形の形をしています。
また、高橋君は M 個の箱を持っています。i 個目の箱は縦 C_i cm 横 D_i cm の長方形の形をしています。

以下の条件を全て満たすように N 枚のチョコレートを全て箱に入れることは可能か判定してください。

  • 1 個の箱に入れることのできるチョコレートの数は、高々 1 個である
  • i 枚目のチョコレートを j 個目の箱に入れるとき、A_i \leq C_j かつ B_i \leq D_j を満たす必要がある(回転は不可)

制約

  • 1 \leq N \leq M \leq 2\times 10^5
  • 1 \leq A_i,B_i,C_i,D_i \leq 10^9
  • 入力は全て整数である

入力

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

N M
A_1 \ldots A_N
B_1 \ldots B_N
C_1 \ldots C_M
D_1 \ldots D_M

出力

N 枚のチョコレートを全て箱に入れることが可能ならば Yes と、不可能ならば No と出力せよ。


入力例 1

2 3
2 4
3 2
8 1 5
2 10 5

出力例 1

Yes

1 枚目のチョコレートを 3 個目の箱に入れて、2 枚目のチョコレートを 1 個目の箱に入れればよいです。


入力例 2

2 2
1 1
2 2
100 1
100 1

出力例 2

No

1 個の箱に入れることのできるチョコレートの数は、高々 1 個です。


入力例 3

1 1
10
100
100
10

出力例 3

No

入力例 4

1 1
10
100
10
100

出力例 4

Yes

Score : 500 points

Problem Statement

Takahashi has N pieces of chocolate. The i-th piece has a rectangular shape with a width of A_i centimeters and a length of B_i centimeters.
He also has M boxes. The i-th box has a rectangular shape with a width of C_i centimeters and a length of D_i centimeters.

Determine whether it is possible to put the N pieces of chocolate in the boxes under the conditions below.

  • A box can contain at most one piece of chocolate.
  • A_i \leq C_j and B_i \leq D_j must hold when putting the i-th piece of chocolate in the j-th box (they cannot be rotated).

Constraints

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

Input

Input is given from Standard Input in the following format:

N M
A_1 \ldots A_N
B_1 \ldots B_N
C_1 \ldots C_M
D_1 \ldots D_M

Output

If it is possible to put the N pieces of chocolate in the boxes, print Yes; otherwise, print No.


Sample Input 1

2 3
2 4
3 2
8 1 5
2 10 5

Sample Output 1

Yes

We can put the first piece of chocolate in the third box and the second piece in the first box.


Sample Input 2

2 2
1 1
2 2
100 1
100 1

Sample Output 2

No

A box can contain at most one piece of chocolate.


Sample Input 3

1 1
10
100
100
10

Sample Output 3

No

Sample Input 4

1 1
10
100
10
100

Sample Output 4

Yes
F - Endless Walk

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

配点 : 500

問題文

N 頂点 M 辺からなる単純な有向グラフ G があり、頂点には頂点 1, 頂点 2, \ldots, 頂点 N と番号がついています。 また、i (1\leq i\leq M) 本目の辺は頂点 U_i から頂点 V_i へ張られています。

高橋君がある頂点から始めて、G の上を有向辺に沿って頂点から頂点へ移動することを繰り返します。 G の頂点のうち、高橋君がうまく経路を選ぶことで、その頂点から始めていくらでも移動を繰り返すことができるようなものの個数を求めてください。

制約

  • 1 \leq N \leq 2\times 10^5
  • 0 \leq M \leq \min(N(N-1), 2\times 10^5)
  • 1 \leq U_i,V_i\leq N
  • U_i\neq V_i
  • i\neq j ならば (U_i,V_i)\neq (U_j,V_j)
  • 入力はすべて整数である。

入力

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

N M
U_1 V_1
U_2 V_2
\vdots
U_M V_M

出力

答えを出力せよ。


入力例 1

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

出力例 1

4

頂点 2 を始点とした場合、頂点 2 \to 頂点 3 \to 頂点 4 \to 頂点 2 \to 頂点 3 \to \cdots と高橋君はいくらでも移動を繰り返す事ができます。 頂点 3, 頂点 4 を始点とした場合も同様です。 頂点 1 からは最初に頂点 2 に移動して、以下同様にいくらでも行動を繰り返すことができます。
一方、頂点 5 からは一度も移動することができません。

よって、条件を満たすのは頂点 1, 2, 3, 44 つであるので、 4 を出力します。


入力例 2

3 2
1 2
2 1

出力例 2

2

単純な有向グラフにおいて、2 つの頂点の間を互いに逆向きに結ぶ辺が、ともに存在する事はあり得ることに注意してください。 また、G は連結であるとは限りません。

Score : 500 points

Problem Statement

We have a simple directed graph G with N vertices and M edges. The vertices are labeled as Vertex 1, Vertex 2, \ldots, Vertex N. The i-th edge (1\leq i\leq M) goes from Vertex U_i to Vertex V_i.

Takahashi will start at a vertex and repeatedly travel on G from one vertex to another along a directed edge. How many vertices of G have the following condition: Takahashi can start at that vertex and continue traveling indefinitely by carefully choosing the path?

Constraints

  • 1 \leq N \leq 2\times 10^5
  • 0 \leq M \leq \min(N(N-1), 2\times 10^5)
  • 1 \leq U_i,V_i\leq N
  • U_i\neq V_i
  • (U_i,V_i)\neq (U_j,V_j) if i\neq j.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
U_1 V_1
U_2 V_2
\vdots
U_M V_M

Output

Print the answer.


Sample Input 1

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

Sample Output 1

4

When starting at Vertex 2, Takahashi can continue traveling indefinitely: 2 \to 3 \to 4 \to 2 \to 3 \to \cdots The same goes when starting at Vertex 3 or Vertex 4. From Vertex 1, he can first go to Vertex 2 and then continue traveling indefinitely again.
On the other hand, from Vertex 5, he cannot move at all.

Thus, four vertices ―Vertex 1, 2, 3, and 4― satisfy the conditions, so 4 should be printed.


Sample Input 2

3 2
1 2
2 1

Sample Output 2

2

Note that, in a simple directed graph, there may be two edges in opposite directions between the same pair of vertices. Additionally, G may not be connected.

G - Foreign Friends

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

配点 : 600

問題文

N 人の人と K 個の国があり、それぞれ 人 1, 人 2, \ldots, 人 N および国 1, 国 2, \ldots, 国 K と番号が付いています。 それぞれの人はちょうど 1 つの国に属しており、人 i は国 A_i に属しています。 また、L 人の人気者がおり、具体的には人 B_1, 人 B_2, \ldots, 人 B_L が人気者です。 最初、N 人のうちどの 2 人も友達ではありません。

神様である高橋君は、M 個の 2 人組のペアについて、コストを支払うことで互いに友達にすることができます。 具体的には 1\leq i\leq M について、コスト C_i を支払うことで人 U_i と人 V_i を互いに友達にすることができます。

ここで、各 1\leq i\leq N について、次の問題を解いてください。

高橋君は、人 i を、人 i の属する国とは異なる国に属する人気者と間接的に友達にすることは可能か? 可能ならば、それを達成するのに必要なコストの総和の最小値を求めよ。 ただし、人 s と人 t が間接的に友達であるとは、ある非負整数 n と人の列 (u_0, u_1, \ldots , u_n) が存在し, u_0=s, u_n=t かつ 0\leq i < n について、人 u_i と 人 u_{i+1} が互いに友達であることをさす。

制約

  • 2 \leq N \leq 10^5
  • 1 \leq M \leq 10^5
  • 1 \leq K \leq 10^5
  • 1 \leq L \leq N
  • 1 \leq A_i \leq K
  • 1 \leq B_1<B_2<\cdots<B_L\leq N
  • 1\leq C_i\leq 10^9
  • 1\leq U_i<V_i\leq N
  • i \neq j ならば (U_i, V_i)\neq (U_j,V_j)
  • 入力は全て整数である。

入力

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

N M K L
A_1 A_2 \cdots A_N
B_1 B_2 \cdots B_L
U_1 V_1 C_1
U_2 V_2 C_2
\vdots
U_M V_M C_M

出力

X_i を、人 i を異なる国に属する人気者と間接的に友達にすることが不可能ならば -1、 そうでないならば、達成するのに必要な最小コストの値として定義する。 X_1,X_2,\ldots ,X_N を空白区切りで一行に出力せよ。


入力例 1

4 4 2 2
1 1 2 2
2 3
1 2 15
2 3 30
3 4 40
1 4 10

出力例 1

45 30 30 25

1, 人 2, 人 3, 人 4 はそれぞれ国 1, 国 1, 国 2, 国 2 に属しており、人気者は人 2, 人 32 名です。このとき、

  • 1 と異なる国に属する人気者は人 3 のみです。人 1 と 人 3 を間接的に友達にするには、それぞれコスト 15,30 を払って人 1 と人 2, 人 2 と人 3 を友達にした時がかかるコストが最小で、このとき 15+30=45 となります。
  • 2 と異なる国に属する人気者は人 3 のみです。コスト 30 を払って人 2 と人 3 を友達にした時が最小となります。
  • 3 と異なる国に属する人気者は人 2 のみです。コスト 30 を払って人 2 と人 3 を友達にした時が最小となります。
  • 4 と異なる国に属する人気者は人 2 のみです。人 4 と 人 2 を間接的に友達にするには、それぞれコスト 15,10 を払って人 1 と人 2, 人 1 と人 4 を友達にした時がかかるコストが最小で、このとき 15+10=25 となります。

入力例 2

3 1 3 1
1 2 3
1
1 2 1000000000

出力例 2

-1 1000000000 -1

1 にとって自身は間接的な友達といえますが、異なる国に属していないため、 「異なる国に属する人気者」の条件をみたす相手はいないことに注意してください。

Score : 600 points

Problem Statement

There are N people and K nations, labeled as Person 1, Person 2, \ldots, Person N and Nation 1, Nation 2, \ldots, Nation K, respectively.
Each person belongs to exactly one nation: Person i belongs to Nation A_i. Additionally, there are L popular people among them: Person B_1, Person B_2, \ldots, Person B_L are popular. Initially, no two of the N people are friends.

For M pairs of people, Takahashi, a God, can make them friends by paying a certain cost: for each 1\leq i\leq M, he can pay the cost of C_i to make Person U_i and Person V_i friends.

Now, for each 1\leq i\leq N, solve the following problem.

Can Takahashi make Person i an indirect friend of a popular person belonging to a nation different from that of Person i? If he can do so, find the minimum total cost needed. Here, Person s is said to be an indirect friend of Person t when there exists a non-negative integer n and a sequence of people (u_0, u_1, \ldots, u_n) such that u_0=s, u_n=t, and Person u_i and Person u_{i+1} are friends for each 0\leq i < n.

Constraints

  • 2 \leq N \leq 10^5
  • 1 \leq M \leq 10^5
  • 1 \leq K \leq 10^5
  • 1 \leq L \leq N
  • 1 \leq A_i \leq K
  • 1 \leq B_1<B_2<\cdots<B_L\leq N
  • 1\leq C_i\leq 10^9
  • 1\leq U_i<V_i\leq N
  • (U_i, V_i)\neq (U_j,V_j) if i \neq j.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K L
A_1 A_2 \cdots A_N
B_1 B_2 \cdots B_L
U_1 V_1 C_1
U_2 V_2 C_2
\vdots
U_M V_M C_M

Output

Let X_i defined as follows: X_i is -1 if it is impossible to make Person i an indirect friend of a popular person belonging to a nation different from that of Person i; otherwise, X_i is the minimum total cost needed to do so. Print X_1, X_2, \ldots, X_N in one line, with spaces in between.


Sample Input 1

4 4 2 2
1 1 2 2
2 3
1 2 15
2 3 30
3 4 40
1 4 10

Sample Output 1

45 30 30 25

Person 1, 2, 3, 4 belong to Nation 1, 1, 2, 2, respectively, and there are two popular people: Person 2 and 3. Here,

  • For Person 1, the only popular person belonging to a different nation is Person 3. To make them indirect friends with the minimum cost, we should pay the cost of 15 to make Person 1 and 2 friends and pay 30 to make Person 2 and 3 friends, for a total of 15+30=45.
  • For Person 2, the only popular person belonging to a different nation is Person 3. The minimum cost is achieved by making Person 2 and 3 friends by paying 30.
  • For Person 3, the only popular person belonging to a different nation is Person 2. The minimum cost is achieved by making Person 2 and 3 friends by paying 30.
  • For Person 4, the only popular person belonging to a different nation is Person 2. To make them indirect friends with the minimum cost, we should pay the cost of 15 to make Person 1 and 2 friends and pay 10 to make Person 1 and 4 friends, for a total of 15+10=25.

Sample Input 2

3 1 3 1
1 2 3
1
1 2 1000000000

Sample Output 2

-1 1000000000 -1

Note that, for Person 1, Person 1 itself is indeed an indirect friend, but it does not belong to a different nation, so there is no popular person belonging to a different nation.

Ex - Product Modulo 2

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

配点 : 600

問題文

長さ K の整数からなる数列 A=(A_1,\ldots,A_K) のうち、以下の条件を全て満たすものは何通りありますか?
998244353 で割った余りを求めてください。

  • すべての i(1\leq i\leq K) について、0\leq A_i \leq M-1

  • \displaystyle\prod_{i=1}^{K} A_i \equiv N \pmod M

制約

  • 1 \leq K \leq 10^9
  • 0 \leq N \lt M \leq 10^{12}
  • 入力は全て整数である

入力

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

K N M

出力

答えを出力せよ。


入力例 1

2 3 6

出力例 1

5

条件を満たす A は、(1,3),(3,1),(3,3),(3,5),(5,3)5 つです。


入力例 2

10 0 2

出力例 2

1023

入力例 3

1000000000 20220326 1000000000000

出力例 3

561382653

998244353 で割った余りを求めてください。

Score : 600 points

Problem Statement

Among the sequences of length K consisting of integers, A=(A_1, \ldots, A_K), how many satisfy all of the conditions below?
Find the count modulo 998244353.

  • 0\leq A_i \leq M-1 for every i(1\leq i\leq K).

  • \displaystyle\prod_{i=1}^{K} A_i \equiv N \pmod M.

Constraints

  • 1 \leq K \leq 10^9
  • 0 \leq N \lt M \leq 10^{12}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

K N M

Output

Print the answer.


Sample Input 1

2 3 6

Sample Output 1

5

The five sequences A satisfying the conditions are (1,3),(3,1),(3,3),(3,5),(5,3).


Sample Input 2

10 0 2

Sample Output 2

1023

Sample Input 3

1000000000 20220326 1000000000000

Sample Output 3

561382653

Be sure to find the count modulo 998244353.