A - Conflict

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

N 個の商品があります。高橋君と青木君がどの商品を欲しがっているかを表す長さ N の文字列 T,A が与えられます。T,Ai\ (1\leq i\leq N) 文字目をそれぞれ T_i,A_i とします。

高橋君は T_io のとき i 番目の商品を欲しがっており、T_ix のとき i 番目の商品を欲しがっていません。 同様に、青木君は A_io のとき i 番目の商品を欲しがっており、A_ix のとき i 番目の商品を欲しがっていません。

2 人ともが欲しがっている商品が存在するか判定してください。

制約

  • 1\leq N\leq 100
  • N は整数
  • T,Ao および x からなる長さ N の文字列

入力

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

N
T
A

出力

2 人とも欲しがっている商品が存在するならば Yes を、存在しないならば No を出力せよ。


入力例 1

4
oxoo
xoox

出力例 1

Yes

3 つ目の商品は 2 人ともが欲しがっているため、Yes を出力します。


入力例 2

5
xxxxx
ooooo

出力例 2

No

2 人とも欲しがっている商品は存在しないため、No を出力します。


入力例 3

10
xoooxoxxxo
ooxooooxoo

出力例 3

Yes

Score : 100 points

Problem Statement

There are N items. You are given strings T and A of length N that represent which items Takahashi and Aoki want, respectively. Let T_i and A_i be the i-th (1\leq i\leq N) characters of T and A, respectively.

Takahashi wants the i-th item when T_i is o, and does not want the i-th item when T_i is x. Similarly, Aoki wants the i-th item when A_i is o, and does not want the i-th item when A_i is x.

Determine whether there exists an item that both of them want.

Constraints

  • 1\leq N\leq 100
  • N is an integer.
  • T and A are strings of length N consisting of o and x.

Input

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

N
T
A

Output

If there exists an item that both of them want, output Yes; otherwise, output No.


Sample Input 1

4
oxoo
xoox

Sample Output 1

Yes

The third item is wanted by both of them, so output Yes.


Sample Input 2

5
xxxxx
ooooo

Sample Output 2

No

There is no item that both of them want, so output No.


Sample Input 3

10
xoooxoxxxo
ooxooooxoo

Sample Output 3

Yes
B - Citation

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

長さ N の非負整数列 A=(A_1,A_2,\dots,A_N) が与えられます。次を満たす最大の非負整数 x を求めてください。

  • A に、 x 以上の要素が重複を含めて x 回以上現れる。

制約

  • 1 \leq N \leq 100
  • 0 \leq A_i \leq 10^9
  • 入力はすべて整数

入力

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

N
A_1 A_2 \dots A_N

出力

答えを出力せよ。


入力例 1

3
1 2 1

出力例 1

1

A=(1,2,1)

  • 0 以上の要素は 3
  • 1 以上の要素は 3
  • 2 以上の要素は 1
  • 3 以上の要素は 0

現れます。条件を満たす最大の非負整数は 1 です。


入力例 2

7
1 6 2 10 2 3 2

出力例 2

3

Score : 200 points

Problem Statement

You are given a sequence of non-negative integers A=(A_1,A_2,\dots,A_N) of length N. Find the maximum non-negative integer x that satisfies the following:

  • In A, elements greater than or equal to x appear at least x times (including duplicates).

Constraints

  • 1 \leq N \leq 100
  • 0 \leq A_i \leq 10^9
  • All input values are integers.

Input

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

N
A_1 A_2 \dots A_N

Output

Output the answer.


Sample Input 1

3
1 2 1

Sample Output 1

1

In A=(1,2,1):

  • Elements greater than or equal to 0 appear 3 times.
  • Elements greater than or equal to 1 appear 3 times.
  • Elements greater than or equal to 2 appear 1 time.
  • Elements greater than or equal to 3 appear 0 times.

The maximum non-negative integer that satisfies the condition is 1.


Sample Input 2

7
1 6 2 10 2 3 2

Sample Output 2

3
C - Equilateral Triangle

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

円周が L の円があり、この円周上に点 1,2,\ldots,N が配置されています。i=1,2,\ldots,N-1 に対し、点 i+1 は点 i から時計回りに円周上を d_i 進んだ位置にあります。

整数の組 (a,b,c)\ (1\leq a\lt b\lt c\leq N) であって、以下の 2 つをともに満たすものの個数を求めてください。

  • 3a,b,c はすべて異なる位置にある。
  • 3a,b,c を頂点とする三角形は正三角形である。

制約

  • 3\leq L,N\leq 3\times 10^5
  • 0\leq d_i\lt L
  • 入力は全て整数

入力

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

N L
d_1 d_2 \ldots d_{N-1}

出力

答えを出力せよ。


入力例 1

5 6
4 3 1 2

出力例 1

2

5 つの点の配置は以下のようになります。条件を満たすのは (a,b,c)=(1,2,4),(1,4,5)2 つです。


入力例 2

4 4
1 1 1

出力例 2

0

入力例 3

10 12
4 4 5 7 1 7 0 8 5

出力例 3

13

Score : 300 points

Problem Statement

There is a circle with circumference L, and points 1,2,\ldots,N are placed on this circle. For i=1,2,\ldots,N-1, point i+1 is located at a position that is d_i clockwise from point i on the circle.

Find the number of integer triples (a,b,c)\ (1\leq a\lt b\lt c\leq N) that satisfy both of the following conditions:

  • The three points a, b, and c are all at different positions.
  • The triangle with vertices at the three points a, b, and c is an equilateral triangle.

Constraints

  • 3\leq L,N\leq 3\times 10^5
  • 0\leq d_i\lt L
  • All input values are integers.

Input

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

N L
d_1 d_2 \ldots d_{N-1}

Output

Output the answer.


Sample Input 1

5 6
4 3 1 2

Sample Output 1

2

The arrangement of the five points is as follows. Two pairs satisfy the conditions: (a,b,c)=(1,2,4),(1,4,5).


Sample Input 2

4 4
1 1 1

Sample Output 2

0

Sample Input 3

10 12
4 4 5 7 1 7 0 8 5

Sample Output 3

13
D - String Rotation

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

長さ N の英小文字からなる文字列 S=S_1S_2\dots S_N が与えられます。あなたは、S に対して以下の操作をちょうど 1 回行います。

  • S の長さ 1 以上の連続部分文字列を選んで、左に 1 だけ巡回シフトする。すなわち、整数 1 \leq \ell \leq r \leq N を選んで、Sr 文字目の右に S_\ell を挿入したのち、S\ell 番目の文字を削除する。

操作後の S としてありえる文字列のうち、辞書順最小のものを求めてください。

T 個のテストケースが与えられるので、それぞれについて答えてください。

制約

  • 1 \leq T \leq 10^5
  • 1 \leq N \leq 10^5
  • S は英小文字からなる長さ N の文字列
  • T,N は整数
  • 1 つの入力ファイルに含まれる N の総和は 10^5 以下

入力

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

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

各テストケース \mathrm{case}_i\;(1 \leq i \leq T) は以下の形式で与えられる。

N
S

出力

T 行出力せよ。i \; (1 \leq i \leq T) 行目には、\mathrm{case}_i に対する答えを出力せよ。


入力例 1

3
7
atcoder
1
x
5
snuke

出力例 1

acodert
x
nsuke
  • 1 番目のテストケースでは、2 文字目から 7 文字目を巡回シフトして acodert とするのが辞書順最小です。
  • 2 番目のテストケースでは、どのように操作しても x が得られます。
  • 3 番目のテストケースでは、1 文字目から 2 文字目を巡回シフトして nsuke とするのが辞書順最小です。

Score : 400 points

Problem Statement

You are given a string S=S_1S_2\dots S_N of length N consisting of lowercase English letters. You will perform the following operation on S exactly once:

  • Choose a contiguous substring of S with length at least 1 and cyclically shift it to the left by 1. That is, choose integers 1 \leq \ell \leq r \leq N, insert S_\ell to the right of the r-th character of S, and then delete the \ell-th character of S.

Find the lexicographically smallest string among all possible strings that S can become after the operation.

You are given T test cases, so solve each of them.

Constraints

  • 1 \leq T \leq 10^5
  • 1 \leq N \leq 10^5
  • S is a string of length N consisting of lowercase English letters.
  • T and N are integers.
  • The sum of N over all test cases in a single input file is at most 10^5.

Input

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

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

Each test case \mathrm{case}_i\;(1 \leq i \leq T) is given in the following format:

N
S

Output

Output T lines. The i-th (1 \leq i \leq T) line should contain the answer for \mathrm{case}_i.


Sample Input 1

3
7
atcoder
1
x
5
snuke

Sample Output 1

acodert
x
nsuke
  • In the first test case, cyclically shifting from the 2nd to the 7th character gives acodert, which is lexicographically smallest.
  • In the second test case, no matter how you operate, you get x.
  • In the third test case, cyclically shifting from the 1st to the 2nd character gives nsuke, which is lexicographically smallest.
E - Pair Annihilation

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 425

問題文

N 頂点の木が与えられます。頂点には 1,2,\dots,N の番号が、辺には 1,2,\dots,N-1 の番号がついています。辺 j は頂点 u_j,v_j を双方向に結び、重み w_j を持ちます。また、頂点 i には整数 x_i が与えられており、x_i > 0 なら x_i 個の陽電子が、x_i < 0 なら -x_i 個の電子が頂点 i に置かれています。x_i=0 ならば頂点 i には何もありません。ここで、\sum_{i=1}^N x_i = 0 が保証されます。

陽電子または電子 1 個を辺 j に沿って動かすと、エネルギー w_j がかかります。また、陽電子と電子が同じ頂点にあるとき、それらは同じ数だけ打ち消し合って消滅します。

すべての陽電子と電子を消滅させるために必要なエネルギーの最小値を求めてください。

制約

  • 2 \leq N \leq 10^5
  • |x_i| \leq 10^4
  • \sum_{i=1}^N x_i = 0
  • 1 \leq u_j < v_j \leq N
  • 0 \leq w_j \leq 10^4
  • 与えられるグラフは木である
  • 入力はすべて整数

入力

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

N
x_1 x_2 \dots x_N
u_1 v_1 w_1
u_2 v_2 w_2
\vdots
u_{N-1} v_{N-1} w_{N-1}

出力

答えを出力せよ。


入力例 1

4
-3 2 2 -1
1 2 2
1 3 1
1 4 3

出力例 1

9

はじめ、x=(x_1,x_2,x_3,x_4)=(-3,+2,+2,-1) です。 次のように操作することで、エネルギー 9 ですべての陽電子と電子を消滅させることができます。

  • 頂点 1 にある電子を 1 つ、頂点 2 に移動させる。エネルギー 2 がかかり、x=(-2,+1,+2,-1) となる。
  • 頂点 2 にある陽電子を 1 つ、頂点 1 に移動させる。エネルギー 2 がかかり、x=(-1,0,+2,-1) となる。
  • 頂点 4 にある電子を 1 つ、頂点 1 に移動させる。エネルギー 3 がかかり、x=(-2,0,+2,0) となる。
  • 頂点 1 にある電子を 1 つ、頂点 3 に移動させる。エネルギー 1 がかかり、x=(-1,0,+1,0) となる。
  • 頂点 1 にある電子を 1 つ、頂点 3 に移動させる。エネルギー 1 がかかり、x=(0,0,0,0) となる。

8 以下のエネルギーですべての陽電子と電子を消滅させることはできないため、答えは 9 です。


入力例 2

2
0 0
1 2 1

出力例 2

0

はじめから条件が満たされている場合もあります。


入力例 3

5
-2 -8 10 -2 2
3 5 1
1 3 5
2 5 0
3 4 6

出力例 3

28

Score : 425 points

Problem Statement

You are given a tree with N vertices. The vertices are numbered 1,2,\dots,N, and the edges are numbered 1,2,\dots,N-1. Edge j bidirectionally connects vertices u_j and v_j and has weight w_j. Also, vertex i is given an integer x_i. If x_i > 0, then x_i positrons are placed at vertex i. If x_i < 0, then -x_i electrons are placed at vertex i. If x_i=0, then nothing is placed at vertex i. Here, it is guaranteed that \sum_{i=1}^N x_i = 0.

Moving one positron or electron along edge j costs energy w_j. Also, when a positron and an electron are at the same vertex, they annihilate each other in equal numbers.

Find the minimum energy required to annihilate all positrons and electrons.

Constraints

  • 2 \leq N \leq 10^5
  • |x_i| \leq 10^4
  • \sum_{i=1}^N x_i = 0
  • 1 \leq u_j < v_j \leq N
  • 0 \leq w_j \leq 10^4
  • The given graph is a tree.
  • All input values are integers.

Input

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

N
x_1 x_2 \dots x_N
u_1 v_1 w_1
u_2 v_2 w_2
\vdots
u_{N-1} v_{N-1} w_{N-1}

Output

Output the answer.


Sample Input 1

4
-3 2 2 -1
1 2 2
1 3 1
1 4 3

Sample Output 1

9

Initially, x=(x_1,x_2,x_3,x_4)=(-3,+2,+2,-1). By operating as follows, all positrons and electrons can be annihilated with energy 9:

  • Move one electron at vertex 1 to vertex 2. This costs energy 2, and x=(-2,+1,+2,-1).
  • Move one positron at vertex 2 to vertex 1. This costs energy 2, and x=(-1,0,+2,-1).
  • Move one electron at vertex 4 to vertex 1. This costs energy 3, and x=(-2,0,+2,0).
  • Move one electron at vertex 1 to vertex 3. This costs energy 1, and x=(-1,0,+1,0).
  • Move one electron at vertex 1 to vertex 3. This costs energy 1, and x=(0,0,0,0).

It is impossible to annihilate all positrons and electrons with energy 8 or less, so the answer is 9.


Sample Input 2

2
0 0
1 2 1

Sample Output 2

0

The condition may already be satisfied from the beginning.


Sample Input 3

5
-2 -8 10 -2 2
3 5 1
1 3 5
2 5 0
3 4 6

Sample Output 3

28
F - Connecting Points

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

2 次元平面上に N 頂点 0 辺のグラフ G があります。頂点には 1 から N までの番号が付いており、頂点 i は座標 (x_i,y_i) にあります。

G の頂点 u,v に対して、u,v の距離 d(u,v) をマンハッタン距離 d(u,v)=|x_u-x_v|+|y_u-y_v| で定義します。

また、G2 つの連結成分 A,B に対して、A,B の頂点集合をそれぞれ V(A),V(B) としたとき、A,B の距離 d(A,B)d(A,B)=\min\lbrace d(u,v)\mid u \in V(A), v\in V(B)\rbrace で定義します。

以下で説明されるクエリを Q 個処理してください。クエリは次の 3 種類のいずれかです。

  • 1 a b : G の頂点数を n としたとき、頂点 n+1 の座標を (x_{n+1},y_{n+1})=(a,b) として、G に頂点 n+1 を追加する。
  • 2 : G の頂点数を n、連結成分数を m とする。
    • m=1 のとき、-1 を出力する。
    • m\geq 2 のとき、距離が最小である連結成分をすべてマージし、その最小の距離の値を出力する。厳密には、G の連結成分を A_1,A_2,\ldots,A_m として、\displaystyle k=\min_{1\leq i\lt j\leq m} d(A_i,A_j) とする。同じ連結成分にない頂点の組 (u,v)\ (1\leq u\lt v\leq n) であって d(u,v)=k を満たすようなものすべてについて、頂点 uv の間に辺を張る。その後、k を出力する。
  • 3 u v : 頂点 u,v が同じ連結成分にあるならば Yes を、そうでないならば No を出力する。

制約

  • 2\leq N\leq 1500
  • 1\leq Q\leq 1500
  • 0\leq x_i,y_i\leq 10^9
  • 1 種類目のクエリについて、0\leq a,b\leq 10^9
  • 3 種類目のクエリについて、そのクエリを処理する直前の G の頂点数を n としたとき、1\leq u\lt v\leq n
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。\mathrm{query}_ii 番目に処理するクエリである。

N Q
x_1 y_1
x_2 y_2
\vdots
x_N y_N
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q

各クエリは以下の 3 種類のいずれかの形式で与えられる。

1 a b
2
3 u v

出力

問題文の指示に従ってクエリへの答えを改行区切りで出力せよ。


入力例 1

4 11
3 4
3 3
7 3
2 2
3 1 2
2
3 1 2
1 6 4
2
3 2 5
2
3 2 5
2
1 2 2
2

出力例 1

No
1
Yes
2
No
3
Yes
-1
0

はじめ、頂点 1,2,3,4 はそれぞれ座標 (3,4),(3,3),(7,3),(2,2) にあります。

  • 1 番目のクエリについて、頂点 12 は連結でないため、No を出力します。
  • 2 番目のクエリについて、連結成分は 4 つあり、各連結成分に含まれる頂点集合は \lbrace 1\rbrace, \lbrace 2\rbrace, \lbrace 3\rbrace, \lbrace 4\rbrace です。異なる連結成分間の距離の最小値は 1 であり、頂点 12 の間に辺が張られます。1 を出力します。
  • 3 番目のクエリについて、頂点 12 は連結であるため、Yes を出力します。
  • 4 番目のクエリについて、座標 (6,4) に頂点 5 を追加します。
  • 5 番目のクエリについて、連結成分は 4 つあり、各連結成分に含まれる頂点集合は \lbrace 1,2\rbrace,\lbrace 3\rbrace,\lbrace 4\rbrace,\lbrace 5\rbrace です。異なる連結成分間の距離の最小値は 2 であり、頂点 24 の間および頂点 35 の間に辺が張られます。2 を出力します。
  • 6 番目のクエリについて、頂点 25 は連結でないため、No を出力します。
  • 7 番目のクエリについて、連結成分は 2 つあり、各連結成分に含まれる頂点集合は \lbrace 1,2,4\rbrace,\lbrace 3,5\rbrace です。異なる連結成分間の距離の最小値は 3 であり、頂点 15 の間に辺が張られます。3 を出力します。
  • 8 番目のクエリについて、頂点 25 は連結であるため、Yes を出力します。
  • 9 番目のクエリについて、連結成分は 1 つであるため -1 を出力します。
  • 10 番目のクエリについて、座標 (2,2) に頂点 6 を追加します。
  • 11 番目のクエリについて、連結成分は 2 つあり、各連結成分に含まれる頂点集合は \lbrace 1,2,3,4,5\rbrace,\lbrace 6\rbrace です。異なる連結成分間の距離の最小値は 0 であり、頂点 46 の間に辺が張られます。0 を出力します。

Score : 500 points

Problem Statement

There is a graph G with N vertices and 0 edges on a 2-dimensional plane. The vertices are numbered from 1 to N, and vertex i is located at coordinates (x_i,y_i).

For vertices u and v of G, the distance d(u,v) between u and v is defined as the Manhattan distance d(u,v)=|x_u-x_v|+|y_u-y_v|.

Also, for two connected components A and B of G, let V(A) and V(B) be the vertex sets of A and B, respectively. The distance d(A,B) between A and B is defined as d(A,B)=\min\lbrace d(u,v)\mid u \in V(A), v\in V(B)\rbrace.

Process Q queries as described below. Each query is one of the following three types:

  • 1 a b : Let n be the number of vertices in G. Add vertex n+1 to G with coordinates (x_{n+1},y_{n+1})=(a,b).
  • 2 : Let n be the number of vertices in G and m be the number of connected components.
    • If m=1, output -1.
    • If m\geq 2, merge all connected components with the minimum distance and output the value of that minimum distance. Formally, let the connected components of G be A_1,A_2,\ldots,A_m and let \displaystyle k=\min_{1\leq i\lt j\leq m} d(A_i,A_j). For all pairs of vertices (u,v)\ (1\leq u\lt v\leq n) that are not in the same connected component and satisfy d(u,v)=k, add an edge between vertices u and v. Then, output k.
  • 3 u v : If vertices u and v are in the same connected component, output Yes; otherwise, output No.

Constraints

  • 2\leq N\leq 1500
  • 1\leq Q\leq 1500
  • 0\leq x_i,y_i\leq 10^9
  • For queries of type 1, 0\leq a,b\leq 10^9.
  • For queries of type 3, let n be the number of vertices in G just before processing that query, then 1\leq u\lt v\leq n.
  • All input values are integers.

Input

The input is given from Standard Input in the following format, where \mathrm{query}_i is the i-th query to be processed.

N Q
x_1 y_1
x_2 y_2
\vdots
x_N y_N
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q

Each query is given in one of the following three formats:

1 a b
2
3 u v

Output

Output the answers to the queries separated by newlines, following the instructions in the problem statement.


Sample Input 1

4 11
3 4
3 3
7 3
2 2
3 1 2
2
3 1 2
1 6 4
2
3 2 5
2
3 2 5
2
1 2 2
2

Sample Output 1

No
1
Yes
2
No
3
Yes
-1
0

Initially, vertices 1,2,3,4 are located at coordinates (3,4),(3,3),(7,3),(2,2), respectively.

  • For the 1st query, vertices 1 and 2 are not connected, so output No.
  • For the 2nd query, there are 4 connected components, and the vertex set of each connected component is \lbrace 1\rbrace, \lbrace 2\rbrace, \lbrace 3\rbrace, \lbrace 4\rbrace. The minimum distance between different connected components is 1, and an edge is added between vertices 1 and 2. Output 1.
  • For the 3rd query, vertices 1 and 2 are connected, so output Yes.
  • For the 4th query, add vertex 5 at coordinates (6,4).
  • For the 5th query, there are 4 connected components, and the vertex set of each connected component is \lbrace 1,2\rbrace,\lbrace 3\rbrace,\lbrace 4\rbrace,\lbrace 5\rbrace. The minimum distance between different connected components is 2, and edges are added between vertices 2 and 4 and between vertices 3 and 5. Output 2.
  • For the 6th query, vertices 2 and 5 are not connected, so output No.
  • For the 7th query, there are 2 connected components, and the vertex set of each connected component is \lbrace 1,2,4\rbrace,\lbrace 3,5\rbrace. The minimum distance between different connected components is 3, and an edge is added between vertices 1 and 5. Output 3.
  • For the 8th query, vertices 2 and 5 are connected, so output Yes.
  • For the 9th query, there is 1 connected component, so output -1.
  • For the 10th query, add vertex 6 at coordinates (2,2).
  • For the 11th query, there are 2 connected components, and the vertex set of each connected component is \lbrace 1,2,3,4,5\rbrace,\lbrace 6\rbrace. The minimum distance between different connected components is 0, and an edge is added between vertices 4 and 6. Output 0.
G - Accumulation of Wealth

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 625

問題文

2 以上の整数 N と、0 以上 100 以下の整数 P が与えられます。以下、 p=P/100 とします。

数列 A があります。はじめ、A の長さは 1 で、唯一の要素は 1 です。

数列 A に対して、以下の操作を N-1 回繰り返します。

  • A に現れない最小の正整数を m とする。確率 p で操作 1、確率 1-p で操作 2 を行う:
    • 操作 1: A の末尾に m を追加する。
    • 操作 2: 1,2,\dots,m-1A に含まれる個数を c_1,c_2,\dots,c_{m-1} とする。1 以上 m-1 以下の整数 kc_k に比例する確率で 1 つ選ぶ。すなわち、確率 c_k/\sum_{j=1}^{m-1} c_jk を選ぶ。そして、A の末尾に k を追加する。

k=1,2,\dots,N について、N-1 回の操作後に A に含まれる k の個数の期待値を \mathrm{mod}\; 998244353 で求めてください。

期待値 \pmod{998244353} の定義

求める期待値は必ず有理数になることが証明できます。 また、この問題の制約のもとでは、その値を既約分数 \frac{P}{Q} で表した時、Q \neq 0 \pmod{998244353} となることも証明できます。 よって、R \times Q \equiv P \pmod{998244353}, 0 \leq R \lt 998244353 を満たす整数 R が一意に定まります。 この R を答えてください。

制約

  • 2 \leq N \leq 10^5
  • 0 \leq P \leq 100
  • 入力はすべて整数

入力

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

N P

出力

N 行出力せよ。k\;(1\leq k \leq N) 行目には、操作後の A に含まれる k の個数の期待値を \mathrm{mod}\; 998244353 で出力せよ。


入力例 1

3 50

出力例 1

124780546
124780545
748683265

操作は以下のように進行します。

  • はじめ、 A=(1) です。
  • 1 回目の操作:確率 1/2A=(1,2)、確率 1/2A=(1,1) となります。
  • 2 回目の操作
    • A=(1,2) のとき、確率 1/2A=(1,2,3), 確率 1/4A=(1,2,1), 確率 1/4A=(1,2,2) となります。
    • A=(1,1) のとき、確率 1/2A=(1,1,2), 確率 1/2A=(1,1,1) となります。

最終的な A に含まれる 1,2,3 の個数の期待値はそれぞれ \frac{15}{8}, \frac{7}{8}, \frac{1}{4} です。


入力例 2

2 0

出力例 2

2
0

入力例 3

5 24

出力例 3

297734288
442981554
937492320
798158491
518366411

Score : 625 points

Problem Statement

You are given an integer N \geq 2 and an integer P between 0 and 100, inclusive. Let p=P/100.

There is a sequence A. Initially, the length of A is 1, and its only element is 1.

The following operation is repeated N-1 times on sequence A:

  • Let m be the smallest positive integer that does not appear in A. With probability p, perform operation 1; with probability 1-p, perform operation 2:
    • Operation 1: Append m to the end of A.
    • Operation 2: Let c_1,c_2,\dots,c_{m-1} be the number of times 1,2,\dots,m-1 appear in A, respectively. Choose an integer k between 1 and m-1, inclusive, with probability proportional to c_k. That is, choose k with probability c_k/\sum_{j=1}^{m-1} c_j. Then, append k to the end of A.

For each k=1,2,\dots,N, find the expected number of occurrences of k in A after N-1 operations, modulo 998244353.

Definition of expected value modulo 998244353

It can be proved that the expected value you seek is always a rational number. Also, under the constraints of this problem, it can be proved that when this value is expressed as an irreducible fraction \frac{P}{Q}, we have Q \neq 0 \pmod{998244353}. Therefore, there is a unique integer R such that R \times Q \equiv P \pmod{998244353} and 0 \leq R \lt 998244353. Output this R.

Constraints

  • 2 \leq N \leq 10^5
  • 0 \leq P \leq 100
  • All input values are integers.

Input

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

N P

Output

Output N lines. The k-th (1\leq k \leq N) line should contain the expected number of occurrences of k in A after the operations, modulo 998244353.


Sample Input 1

3 50

Sample Output 1

124780546
124780545
748683265

The operations proceed as follows:

  • Initially, A=(1).
  • 1st operation: It becomes A=(1,2) with probability 1/2, and A=(1,1) with probability 1/2.
  • 2nd operation:
    • If A=(1,2), it becomes A=(1,2,3) with probability 1/2, A=(1,2,1) with probability 1/4, and A=(1,2,2) with probability 1/4.
    • If A=(1,1), it becomes A=(1,1,2) with probability 1/2, and A=(1,1,1) with probability 1/2.

The expected numbers of occurrences of 1,2,3 in the final A are \frac{15}{8}, \frac{7}{8}, \frac{1}{4}, respectively.


Sample Input 2

2 0

Sample Output 2

2
0

Sample Input 3

5 24

Sample Output 3

297734288
442981554
937492320
798158491
518366411