A - Spread

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

配点 : 100

問題文

英大文字からなる文字列 S が与えられます。S の各文字を空白で区切り、その順で 1 文字ずつ出力してください。

制約

  • S は長さ 2 以上 100 以下の英大文字からなる文字列

入力

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

S

出力

S の各文字を空白で区切り、1 文字ずつ出力せよ。


入力例 1

ABC

出力例 1

A B C

A, B, C を空白で区切り、1 文字ずつ出力してください。

C の後ろに空白を出力する必要がないことに注意してください。


入力例 2

ZZZZZZZ

出力例 2

Z Z Z Z Z Z Z

入力例 3

OOXXOO

出力例 3

O O X X O O

Score : 100 points

Problem Statement

You are given a string S consisting of uppercase English letters. Separate each character of S with a space and print them one by one in order.

Constraints

  • S is a string consisting of uppercase English letters with a length between 2 and 100, inclusive.

Input

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

S

Output

Separate each character of S with a space and print them one by one.


Sample Input 1

ABC

Sample Output 1

A B C

Separate A, B, and C with spaces and print them one by one.

There is no need to print a space after C.


Sample Input 2

ZZZZZZZ

Sample Output 2

Z Z Z Z Z Z Z

Sample Input 3

OOXXOO

Sample Output 3

O O X X O O
B - Last Card

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

配点 : 100

問題文

1,2,\ldots,N の番号のついた N 人の人に合計 K 枚のカードを配ります。

A から始めて 人 A,A+1,A+2,\ldots,N,1,2,\ldots の順に 1 枚ずつカードを配るとき、最後のカードは誰に配られるでしょうか?

厳密には、人 x(1 \leq x < N) の次には人 x+1 にカードを配り、人 N の次には人 1 にカードを配ります。

制約

  • 1 \leq N,K \leq 1000
  • 1 \leq A \leq N
  • 入力は全て整数

入力

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

N K A

出力

最後のカードが配られた人の番号を出力せよ。


入力例 1

3 3 2

出力例 1

1

2、人 3、人 1 の順にカードを配ります。


入力例 2

1 100 1

出力例 2

1

入力例 3

3 14 2

出力例 3

3

Score : 100 points

Problem Statement

We will hand out a total of K cards to N people numbered 1, 2, \ldots, N.

Beginning with Person A, we will give the cards one by one to the people in this order: A, A+1, A+2, \ldots, N, 1, 2, \ldots. Who will get the last card?

Formally, after Person x(1 \leq x < N) gets a card, Person x+1 will get a card. After Person N gets a card, Person 1 gets a card.

Constraints

  • 1 \leq N,K \leq 1000
  • 1 \leq A \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K A

Output

Print a number representing the person who will get the last card.


Sample Input 1

3 3 2

Sample Output 1

1

The cards are given to Person 2, 3, 1 in this order.


Sample Input 2

1 100 1

Sample Output 2

1

Sample Input 3

3 14 2

Sample Output 3

3
C - Rectangle Detection

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

配点 : 200

問題文

高橋くんは、以下の方法で 10 個の文字列 S_1,S_2,\dots,S_{10} を生成しました。

  • まず、 S_i (1 \le i \le 10)= .......... ( .10 個並んだ文字列) とする。
  • 次に、以下の条件を全て満たす 4 つの整数 A,B,C,D を選ぶ。
    • 1 \le A \le B \le 10
    • 1 \le C \le D \le 10
  • その後、以下の条件を全て満たす全ての整数組 (i,j) について、 S_ij 文字目を # に書き換える。
    • A \le i \le B
    • C \le j \le D

以上の方法で生成された S_1,S_2,\dots,S_{10} が与えられるので、高橋くんが選んだ整数 A,B,C,D を求めてください。
なお、制約より A,B,C,D は一意に定まる (答えはただひとつ存在する) ことが証明できます。

制約

  • S_1,S_2,\dots,S_{10} は問題文中の方法で生成されうるそれぞれ長さ 10 の文字列

入力

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

S_1
S_2
\vdots
S_{10}

出力

答えを以下の形式で出力せよ。

A B
C D

入力例 1

..........
..........
..........
..........
...######.
...######.
...######.
...######.
..........
..........

出力例 1

5 8
4 9

高橋くんが選んだ整数は A=5,B=8,C=4,D=9 です。
このように選ぶことにより、 S_5,S_6,S_7,S_84 文字目から 9 文字目が # であり他の文字が . である 10 個の長さ 10 の文字列 S_1,S_2,\dots,S_{10} が生成されます。
これは入力で与えられた 10 個の文字列と一致します。


入力例 2

..........
..#.......
..........
..........
..........
..........
..........
..........
..........
..........

出力例 2

2 2
3 3

入力例 3

##########
##########
##########
##########
##########
##########
##########
##########
##########
##########

出力例 3

1 10
1 10

Score : 200 points

Problem Statement

Takahashi generated 10 strings S_1,S_2,\dots,S_{10} as follows.

  • First, let S_i (1 \le i \le 10)= .......... (10 .s in a row).
  • Next, choose four integers A, B, C, and D satisfying all of the following.
    • 1 \le A \le B \le 10.
    • 1 \le C \le D \le 10.
  • Then, for every pair of integers (i,j) satisfying all of the following, replace the j-th character of S_i with #.
    • A \le i \le B.
    • C \le j \le D.

You are given S_1,S_2,\dots,S_{10} generated as above. Find the integers A, B, C, and D Takahashi chose.
It can be proved that such integers A, B, C, and D uniquely exist (there is just one answer) under the Constraints.

Constraints

  • S_1,S_2,\dots,S_{10} are strings, each of length 10, that can be generated according to the Problem Statement.

Input

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

S_1
S_2
\vdots
S_{10}

Output

Print the answer in the following format:

A B
C D

Sample Input 1

..........
..........
..........
..........
...######.
...######.
...######.
...######.
..........
..........

Sample Output 1

5 8
4 9

Here, Takahashi chose A=5, B=8, C=4, D=9.
This choice generates 10 strings S_1,S_2,\dots,S_{10}, each of length 10, where the 4-th through 9-th characters of S_5,S_6,S_7,S_8 are #, and the other characters are ..
These are equal to the strings given in the input.


Sample Input 2

..........
..#.......
..........
..........
..........
..........
..........
..........
..........
..........

Sample Output 2

2 2
3 3

Sample Input 3

##########
##########
##########
##########
##########
##########
##########
##########
##########
##########

Sample Output 3

1 10
1 10
D - Base 2

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

配点 : 200

問題文

01 からなる長さ 64 の数列 A=(A_0,A_1,\dots,A_{63}) が与えられます。

A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} を求めてください。

制約

  • A_i0 または 1

入力

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

A_0 A_1 \dots A_{63}

出力

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


入力例 1

1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

出力例 1

13

A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} = 2^0 + 2^2 + 2^3 = 13 です。


入力例 2

1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0

出力例 2

766067858140017173

Score : 200 points

Problem Statement

You are given a sequence A=(A_0,A_1,\dots,A_{63}) of length 64 consisting of 0 and 1.

Find A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63}.

Constraints

  • A_i is 0 or 1.

Input

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

A_0 A_1 \dots A_{63}

Output

Print the answer as an integer.


Sample Input 1

1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Sample Output 1

13

A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} = 2^0 + 2^2 + 2^3 = 13.


Sample Input 2

1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0

Sample Output 2

766067858140017173
E - Find it!

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

配点 : 350

問題文

N 頂点 N 辺の有向グラフがあります。
i 番目の辺は頂点 i から 頂点 A_i に伸びます。 ( i \neq A_i であることは制約より保証されます )
同一頂点を複数回含まない有向閉路をひとつ求めてください。
なお、この問題の制約下で答えが存在することが示せます。

注釈

この問題では、有向閉路とは以下の条件を全て満たす頂点の列 B=(B_1,B_2,\dots,B_M) であるとします。

  • M \ge 2
  • B_i から B_{i+1} に辺が伸びている。 ( 1 \le i \le M-1 )
  • B_M から B_1 に辺が伸びている。
  • i \neq j ならば B_i \neq B_j

制約

  • 入力は全て整数
  • 2 \le N \le 2 \times 10^5
  • 1 \le A_i \le N
  • A_i \neq i

入力

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

N
A_1 A_2 \dots A_N

出力

以下の形式で出力せよ。

M
B_1 B_2 \dots B_M

M は出力する有向閉路の頂点数であり、 B_i は有向閉路の i 番目の頂点である。
出力は以下の条件を満たす必要がある。

  • 2 \le M
  • B_{i+1} = A_{B_i} ( 1 \le i \le M-1 )
  • B_{1} = A_{B_M}
  • B_i \neq B_j ( i \neq j )

答えとして考えられるものが複数ある場合、どれを出力しても正解となる。


入力例 1

7
6 7 2 1 3 4 5

出力例 1

4
7 5 3 2

7 \rightarrow 5 \rightarrow 3 \rightarrow 2 \rightarrow 7 は確かに有向閉路になっています。

この入力に対応するグラフは以下の通りです。

他の正解となる出力の例は以下の通りです。

4
2 7 5 3
3
4 1 6

グラフが連結であるとは限らないことに注意してください。


入力例 2

2
2 1

出力例 2

2
1 2

1 \rightarrow 22 \rightarrow 1 の辺が双方存在するケースです。
この場合、 1 \rightarrow 2 \rightarrow 1 は確かに有向閉路になっています。

この入力に対応するグラフは以下の通りです。
図中 1 \leftrightarrow 21 \rightarrow 22 \rightarrow 1 の辺が双方あることを表現しています。


入力例 3

8
3 7 4 7 3 3 8 2

出力例 3

3
2 7 8

この入力に対応するグラフは以下の通りです。

Score : 350 points

Problem Statement

There is a directed graph with N vertices and N edges.
The i-th edge goes from vertex i to vertex A_i. (The constraints guarantee that i \neq A_i.)
Find a directed cycle without the same vertex appearing multiple times.
It can be shown that a solution exists under the constraints of this problem.

Notes

The sequence of vertices B = (B_1, B_2, \dots, B_M) is called a directed cycle when all of the following conditions are satisfied:

  • M \geq 2
  • The edge from vertex B_i to vertex B_{i+1} exists. (1 \leq i \leq M-1)
  • The edge from vertex B_M to vertex B_1 exists.
  • If i \neq j, then B_i \neq B_j.

Constraints

  • All input values are integers.
  • 2 \le N \le 2 \times 10^5
  • 1 \le A_i \le N
  • A_i \neq i

Input

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

N
A_1 A_2 \dots A_N

Output

Print a solution in the following format:

M
B_1 B_2 \dots B_M

M is the number of vertices, and B_i is the i-th vertex in the directed cycle.
The following conditions must be satisfied:

  • 2 \le M
  • B_{i+1} = A_{B_i} ( 1 \le i \le M-1 )
  • B_{1} = A_{B_M}
  • B_i \neq B_j ( i \neq j )

If multiple solutions exist, any of them will be accepted.


Sample Input 1

7
6 7 2 1 3 4 5

Sample Output 1

4
7 5 3 2

7 \rightarrow 5 \rightarrow 3 \rightarrow 2 \rightarrow 7 is indeed a directed cycle.

Here is the graph corresponding to this input:

Here are other acceptable outputs:

4
2 7 5 3
3
4 1 6

Note that the graph may not be connected.


Sample Input 2

2
2 1

Sample Output 2

2
1 2

This case contains both of the edges 1 \rightarrow 2 and 2 \rightarrow 1.
In this case, 1 \rightarrow 2 \rightarrow 1 is indeed a directed cycle.

Here is the graph corresponding to this input, where 1 \leftrightarrow 2 represents the existence of both 1 \rightarrow 2 and 2 \rightarrow 1:


Sample Input 3

8
3 7 4 7 3 3 8 2

Sample Output 3

3
2 7 8

Here is the graph corresponding to this input:

F - Counting Squares

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

配点 : 300

問題文

二次元平面があります。1 以上 9 以下の整数 r,c について、S_{r}c 番目の文字が # であるとき座標 (r,c) にポーンが置いてあり、S_{r}c 番目の文字が . であるとき座標 (r,c) に何も置かれていません。

この平面上の正方形であって、4 頂点全てにポーンが置いてあるものの個数を求めてください。

制約

  • S_1,\ldots,S_9 はそれぞれ #. からなる長さ 9 の文字列

入力

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

S_1
S_2
\vdots
S_9

出力

答えを出力せよ。


入力例 1

##.......
##.......
.........
.......#.
.....#...
........#
......#..
.........
.........

出力例 1

2

座標 (1,1),(1,2),(2,2),(2,1) を頂点とする正方形は、4 頂点全てにポーンが置かれています。

座標 (4,8),(5,6),(7,7),(6,9) を頂点とする正方形も、4 頂点全てにポーンが置かれています。

よって答えは 2 です。


入力例 2

.#.......
#.#......
.#.......
.........
....#.#.#
.........
....#.#.#
........#
.........

出力例 2

3

Score : 300 points

Problem Statement

There is a two-dimensional plane. For integers r and c between 1 and 9, there is a pawn at the coordinates (r,c) if the c-th character of S_{r} is #, and nothing if the c-th character of S_{r} is ..

Find the number of squares in this plane with pawns placed at all four vertices.

Constraints

  • Each of S_1,\ldots,S_9 is a string of length 9 consisting of # and ..

Input

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

S_1
S_2
\vdots
S_9

Output

Print the answer.


Sample Input 1

##.......
##.......
.........
.......#.
.....#...
........#
......#..
.........
.........

Sample Output 1

2

The square with vertices (1,1), (1,2), (2,2), and (2,1) have pawns placed at all four vertices.

The square with vertices (4,8), (5,6), (7,7), and (6,9) also have pawns placed at all four vertices.

Thus, the answer is 2.


Sample Input 2

.#.......
#.#......
.#.......
.........
....#.#.#
.........
....#.#.#
........#
.........

Sample Output 2

3
G - Distinct Trio

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

配点 : 400

問題文

長さ N の数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
以下の 2 条件をともに満たすような整数の組 (i,j,k) の個数を求めてください。

  • 1\leq i \lt j \lt k \leq N
  • A_i,A_j,A_k は相異なる

制約

  • 3 \leq N \leq 2\times 10^5
  • 1 \leq A_i \leq 2\times 10^5
  • 入力に含まれる値は全て整数である

入力

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

N
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

4
3 1 4 1

出力例 1

2

条件を満たす整数の組 (i,j,k)(1,2,3),(1,3,4)2 つです。


入力例 2

10
99999 99998 99997 99996 99995 99994 99993 99992 99991 99990

出力例 2

120

入力例 3

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

出力例 3

355

Score : 400 points

Problem Statement

You are given a sequence of length N: A=(A_1,A_2,\ldots,A_N).
Find the number of triples (i,j,k) that satisfy both of the following conditions.

  • 1\leq i \lt j \lt k \leq N
  • A_i, A_j, and A_k are distinct.

Constraints

  • 3 \leq N \leq 2\times 10^5
  • 1 \leq A_i \leq 2\times 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

4
3 1 4 1

Sample Output 1

2

The two triples (i,j,k) satisfying the conditions are (1,2,3) and (1,3,4).


Sample Input 2

10
99999 99998 99997 99996 99995 99994 99993 99992 99991 99990

Sample Output 2

120

Sample Input 3

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

Sample Output 3

355
H - Prerequisites

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

配点 : 425

問題文

1 から N までの番号がついた N 冊の本があります。
i には C_i 冊の前提となる本があり、そのうち j 冊目は本 P_{i,j} で、本 i を読む前にこの C_i 冊をすべて読む必要があります。
ただし、適切な順序を選ぶことですべての本を読むことができます。

あなたは本 1 を読むために必要な最小の数の本を読もうとしています。
1 以外に読まなければならない本の番号を読むべき順に出力してください。ただし、この条件下で読むべき本の集合は一意に定まります。
条件を満たす読む順番が複数考えられる場合は、そのいずれを出力しても構いません。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq C_i < N
  • \sum_{i=1}^{N} C_i \leq 2 \times 10^5
  • C_1 \geq 1
  • 1 \leq P_{i,j} \leq N
  • 1 \leq j < k \leq C_i のとき P_{i,j} \neq P_{i,k}
  • すべての本を読むことが可能である

入力

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

N
C_1 P_{1,1} \ldots P_{1,C_1}
C_2 P_{2,1} \ldots P_{2,C_2}
\vdots
C_N P_{N,1} \ldots P_{N,C_N}

出力

1 を読むために読む必要のある最小の数の本を読むとき、それらの番号を読むべき順に空白区切りで出力せよ。


入力例 1

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

出力例 1

5 3 4 2

1 を読むために本 2,3,4、本 2 を読むために本 3,5、本 4 を読むために本 5 を読む必要があります。本 3,5,6 を読むために他の本を読む必要はありません。

このとき、例えば本 5,3,4,2 の順に読むことで本 1 を読むことができます。3 冊以下の本を読んだ状態で本 1 が読めるようになることはないため、これは答えの一つです。他にも本 3,5,4,2 の順などで読むことでも 4 冊の本を読んだ状態で本 1 を読むことができるようになります。


入力例 2

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

出力例 2

6 5 4 3 2

入力例 3

8
1 5
1 6
1 7
1 8
0
0
0
0

出力例 3

5

Score : 425 points

Problem Statement

We have N books numbered 1 to N.
Book i assumes that you have read C_i books, the j-th of which is book P_{i,j}: you must read all these C_i books before reading book i.
Here, you can read all the books in some order.

You are trying to read the minimum number of books required to read book 1.
Print the numbers of the books you must read excluding book 1 in the order they should be read. Under this condition, the set of books to read is uniquely determined.
If there are multiple reading orders that satisfy the condition, you may print any of them.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq C_i < N
  • \sum_{i=1}^{N} C_i \leq 2 \times 10^5
  • C_1 \geq 1
  • 1 \leq P_{i,j} \leq N
  • P_{i,j} \neq P_{i,k} for 1 \leq j < k \leq C_i.
  • It is possible to read all the books.

Input

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

N
C_1 P_{1,1} \ldots P_{1,C_1}
C_2 P_{2,1} \ldots P_{2,C_2}
\vdots
C_N P_{N,1} \ldots P_{N,C_N}

Output

Print the numbers of the books you must read to read book 1 in the order they should be read, with spaces in between.


Sample Input 1

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

Sample Output 1

5 3 4 2

To read book 1, you must read books 2,3,4; to read book 2, you must read books 3,5; to read book 4, you must read book 5. To read books 3,5,6, you do not have to read any other books.

For example, if you read books 5,3,4,2 in this order, you can read book 1. This is a correct answer, because you will never be able to read book 1 with three or fewer books read. As another example, reading books 3,5,4,2 in this order also allows you to read book 1 with 4 books read.


Sample Input 2

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

Sample Output 2

6 5 4 3 2

Sample Input 3

8
1 5
1 6
1 7
1 8
0
0
0
0

Sample Output 3

5
I - Double Chance

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

配点 : 500

問題文

カード 1, カード 2, \ldots, カード NN 枚のカードがあり、 カード i (1\leq i\leq N) には整数 A_i が書かれています。

K=1,2,\ldots,N について、次の問題を解いてください。

カード 1, カード 2, \ldots, カード KK 枚のカードが入っている袋があります。
次の操作を 2 回繰り返し、記録された数を順に x,y とします。

袋から無作為にカードを 1 枚取り出し、カードに書かれている数を記録する。その後、カードを 袋の中に戻す

\max(x,y) の値の期待値を \text{mod} 998244353 で出力してください(注記参照)。
ただし、\max(x,y)xy のうち小さくない方の値を表します。

注記

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

制約

  • 1 \leq N \leq 2\times 10^5
  • 1 \leq A_i \leq 2\times 10^5
  • 入力は全て整数

入力

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

N
A_1 A_2 \ldots A_N

出力

N 行出力せよ。 i 行目 (1\leq i\leq N) には、K=i の時の問題に対する答えを出力せよ。


入力例 1

3
5 7 5

出力例 1

5
499122183
443664163

例えば、K=2 の時の答えは次のようにして求まります。

袋の中にはカード 1 とカード 2 が入っており、それぞれには A_1=5A_2=7 が書かれています。

  • 1 回目に取り出されたカードがカード 12 回目に取り出されたカードもカード 1 のとき、x=y=5 であり、\max(x,y)=5 となります。
  • 1 回目に取り出されたカードがカード 12 回目に取り出されたカードはカード 2 のとき、x=5, y=7 であり、\max(x,y)=7 となります。
  • 1 回目に取り出されたカードがカード 22 回目に取り出されたカードはカード 1 のとき、x=7, y=5 であり、\max(x,y)=7 となります。
  • 1 回目に取り出されたカードがカード 22 回目に取り出されたカードもカード 2 のとき、x=y=7 であり、\max(x,y)=7 となります。

これらが等確率で起こるため、期待値は \frac{5+7+7+7}{4}=\frac{13}{2} となります。 499122183\times 2\equiv 13 \pmod{998244353} であるため、499122183 を出力します。


入力例 2

7
22 75 26 45 72 81 47

出力例 2

22
249561150
110916092
873463862
279508479
360477194
529680742

Score : 500 points

Problem Statement

There are N cards called card 1, card 2, \ldots, card N. On card i (1\leq i\leq N), an integer A_i is written.

For K=1, 2, \ldots, N, solve the following problem.

We have a bag that contains K cards: card 1, card 2, \ldots, card K.
Let us perform the following operation twice, and let x and y be the numbers recorded, in the recorded order.

Draw a card from the bag uniformly at random, and record the number written on that card. Then, return the card to the bag.

Print the expected value of \max(x,y), modulo 998244353 (see Notes).
Here, \max(x,y) denotes the value of the greater of x and y (or x if they are equal).

Notes

It can be proved that the sought expected value is always finite and rational. Additionally, under the Constraints of this problem, when that value is represented as \frac{P}{Q} with two coprime integers P and Q, it can be proved that there is a unique integer R such that R \times Q \equiv P\pmod{998244353} and 0 \leq R \lt 998244353. Print this R.

Constraints

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

Input

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

N
A_1 A_2 \ldots A_N

Output

Print N lines. The i-th line (1\leq i\leq N) should contain the answer to the problem for K=i.


Sample Input 1

3
5 7 5

Sample Output 1

5
499122183
443664163

For instance, the answer for K=2 is found as follows.

The bag contains card 1 and card 2, with A_1=5 and A_2=7 written on them, respectively.

  • If you draw card 1 in the first draw and card 1 again in the second draw, we have x=y=5, so \max(x,y)=5.
  • If you draw card 1 in the first draw and card 2 in the second draw, we have x=5 and y=7, so \max(x,y)=7.
  • If you draw card 2 in the first draw and card 1 in the second draw, we have x=7 and y=5, so \max(x,y)=7.
  • If you draw card 2 in the first draw and card 2 again in the second draw, we have x=y=7, so \max(x,y)=7.

These events happen with the same probability, so the sought expected value is \frac{5+7+7+7}{4}=\frac{13}{2}. We have 499122183\times 2\equiv 13 \pmod{998244353}, so 499122183 should be printed.


Sample Input 2

7
22 75 26 45 72 81 47

Sample Output 2

22
249561150
110916092
873463862
279508479
360477194
529680742