A - Legendary Players

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

AtCoder では、レーティング上位 10 人のハンドルネームには金色の冠が、上位 1 人のハンドルネームには白金色の冠が表示されます。

このコンテストが開始した時点で、アルゴリズム部門での上位 10 人に入っているプレイヤーのハンドルネームとレーティングは以下のようになっています。

tourist 3858
ksun48 3679
Benq 3658
Um_nik 3648
apiad 3638
Stonefeang 3630
ecnerwala 3613
mnbvmar 3555
newbiedmy 3516
semiexp 3481

上記のプレイヤーのハンドルネーム S が与えられるので、その人のレーティングを出力してください。

制約

  • S はアルゴリズム部門でレーティング上位 10 人に入っているプレイヤーのハンドルネームのいずれかと等しい。

入力

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

S

出力

対応するプレイヤーのレーティングを 1 行で出力せよ。


入力例 1

tourist

出力例 1

3858

このコンテストが開始した時点において、 tourist さんのアルゴリズム部門のレーティングは 3858 です。


入力例 2

semiexp

出力例 2

3481

このコンテストが開始した時点において、 semiexp さんのアルゴリズム部門のレーティングは 3481 です。

Score : 100 points

Problem Statement

In AtCoder, the top 10 rated players' usernames are displayed with a gold crown, and the top-rated player's username is displayed with a platinum crown.

At the start of this contest, the usernames and ratings of the top 10 rated players in the algorithm category are as follows:

tourist 3858
ksun48 3679
Benq 3658
Um_nik 3648
apiad 3638
Stonefeang 3630
ecnerwala 3613
mnbvmar 3555
newbiedmy 3516
semiexp 3481

You are given the username S of one of these players. Print that player's rating.

Constraints

  • S is equal to one of the usernames of the top 10 rated players in the algorithm category.

Input

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

S

Output

Print the rating of the corresponding player in one line.


Sample Input 1

tourist

Sample Output 1

3858

At the start of this contest, the rating of tourist in the algorithm category is 3858.


Sample Input 2

semiexp

Sample Output 2

3481

At the start of this contest, the rating of semiexp in the algorithm category is 3481.

B - Lacked Number

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

数字のみからなる、長さがちょうど 9 の文字列 S が与えられます。
S には 0 から 9 までのうち、ちょうど 1 つの数字を除いた 9 種類の数字が一度ずつ登場します。

S に登場しない唯一の数字を出力してください。

制約

  • S は数字のみからなる長さ 9 の文字列である。
  • S の文字はすべて相異なる。

入力

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

S

出力

S に登場しない唯一の数字を出力せよ。


入力例 1

023456789

出力例 1

1

文字列 023456789 には 1 のみが登場していません。 よって、1 を出力します。


入力例 2

459230781

出力例 2

6

文字列 459230781 には 6 のみが登場していません。 よって、6 を出力します。

文字列に数字が現れる順番は昇順とは限らないので注意してください。

Score : 100 points

Problem Statement

You are given a string S of length exactly 9 consisting of digits. One but all digits from 0 to 9 appear exactly once in S.

Print the only digit missing in S.

Constraints

  • S is a string of length 9 consisting of digits.
  • All characters in S are distinct.

Input

Input is given from Standard Input in the following format:

S

Output

Print the only digit missing in S.


Sample Input 1

023456789

Sample Output 1

1

The string 023456789 only lacks 1. Thus, 1 should be printed.


Sample Input 2

459230781

Sample Output 2

6

The string 459230781 only lacks 6. Thus, 6 should be printed.

Note that the digits in the string may not appear in increasing order.

C - Avoid Rook Attack

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

8 マス、横 8 マスの 64 マスからなるマス目があります。 上から i 行目 (1\leq i\leq8) 、左から j 列目 (1\leq j\leq8) のマスをマス (i,j) と呼ぶことにします。

それぞれのマスは、空マスであるかコマが置かれているかのどちらかです。 マスの状態は長さ 8 の文字列からなる長さ 8 の列 (S _ 1,S _ 2,S _ 3,\ldots,S _ 8) で表されます。 マス (i,j) (1\leq i\leq8,1\leq j\leq8) は、S _ ij 文字目が . のとき空マスで、# のときコマが置かれています。

あなたは、すでに置かれているどのコマにも取られないように、いずれかの空マスに自分のコマを置きたいです。

マス (i,j) に置かれているコマは、次のどちらかの条件を満たすコマを取ることができます。

  • i 行目のマスに置かれている
  • j 列目のマスに置かれている

たとえば、マス (4,4) に置かれているコマは、以下の図で青く示されたマスに置かれているコマを取ることができます。

あなたがコマを置くことができるマスがいくつあるか求めてください。

制約

  • S _ i., # からなる長さ 8 の文字列 (1\leq i\leq 8)

入力

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

S _ 1
S _ 2
S _ 3
S _ 4
S _ 5
S _ 6
S _ 7
S _ 8

出力

すでに置かれているコマに取られずに自分のコマを置くことができる空マスの個数を出力せよ。


入力例 1

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

出力例 1

4

すでに置かれているコマは、以下の図で青く示されたマスに置かれたコマを取ることができます。

よって、あなたがすでに置かれているコマに取られないように自分のコマを置くことができるマスはマス (6,6), マス (6,7), マス (7,6), マス (7,7)4 マスです。


入力例 2

........
........
........
........
........
........
........
........

出力例 2

64

コマがひとつも置かれていないこともあります。


入力例 3

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

出力例 3

4

Score : 200 points

Problem Statement

There is a grid of 64 squares with 8 rows and 8 columns. Let (i,j) denote the square at the i-th row from the top (1\leq i\leq8) and j-th column from the left (1\leq j\leq8).

Each square is either empty or has a piece placed on it. The state of the squares is represented by a sequence (S_1,S_2,S_3,\ldots,S_8) of 8 strings of length 8. Square (i,j) (1\leq i\leq8,1\leq j\leq8) is empty if the j-th character of S_i is ., and has a piece if it is #.

You want to place your piece on an empty square in such a way that it cannot be captured by any of the existing pieces.

A piece placed on square (i,j) can capture pieces that satisfy either of the following conditions:

  • Placed on a square in row i
  • Placed on a square in column j

For example, a piece placed on square (4,4) can capture pieces placed on the squares shown in blue in the following figure:

How many squares can you place your piece on?

Constraints

  • Each S_i is a string of length 8 consisting of . and # (1\leq i\leq 8).

Input

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

S_1
S_2
S_3
S_4
S_5
S_6
S_7
S_8

Output

Print the number of empty squares where you can place your piece without it being captured by any existing pieces.


Sample Input 1

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

Sample Output 1

4

The existing pieces can capture pieces placed on the squares shown in blue in the following figure:

Therefore, you can place your piece without it being captured on 4 squares: square (6,6), square (6,7), square (7,6), and square (7,7).


Sample Input 2

........
........
........
........
........
........
........
........

Sample Output 2

64

There may be no pieces on the grid.


Sample Input 3

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

Sample Output 3

4
D - Fill the Gaps

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

正整数からなる長さ N の数列 A=(A_1,\ldots,A_N) があります。どの隣接する 2 項の値も相異なります。

この数列に対し、次の操作によりいくつか数を挿入します。

  1. 数列 A のどの隣接する 2 項の差の絶対値も 1 であるとき、操作を終了する。
  2. 数列 A の先頭から見て、隣接する 2 項の差の絶対値が 1 でない最初の箇所を A_i,A_{i+1} とする。
    • A_i < A_{i+1} ならば、A_iA_{i+1} の間に、A_i+1,A_i+2,\ldots,A_{i+1}-1 を挿入する。
    • A_i > A_{i+1} ならば、A_iA_{i+1} の間に、A_i-1,A_i-2,\ldots,A_{i+1}+1 を挿入する。
  3. 手順 1 に戻る。

操作が終了したときの数列を出力してください。

制約

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 100
  • A_i \neq A_{i+1}
  • 入力は全て整数

入力

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

N
A_1 A_2 \ldots A_N

出力

操作が終了したときの数列の各要素を空白区切りで出力せよ。


入力例 1

4
2 5 1 2

出力例 1

2 3 4 5 4 3 2 1 2

最初、数列は (2,5,1,2) です。操作は以下のように行われます。

  • 1 項目の 22 項目の 5 の間に 3,4 を挿入する。数列は (2,3,4,5,1,2) となる。
  • 4 項目の 55 項目の 1 の間に 4,3,2 を挿入する。数列は (2,3,4,5,4,3,2,1,2) となる。

入力例 2

6
3 4 5 6 5 4

出力例 2

3 4 5 6 5 4

一度も挿入が行われないこともあります。

Score : 200 points

Problem Statement

We have a sequence of length N consisting of positive integers: A=(A_1,\ldots,A_N). Any two adjacent terms have different values.

Let us insert some numbers into this sequence by the following procedure.

  1. If every pair of adjacent terms in A has an absolute difference of 1, terminate the procedure.
  2. Let A_i, A_{i+1} be the pair of adjacent terms nearest to the beginning of A whose absolute difference is not 1.
    • If A_i < A_{i+1}, insert A_i+1,A_i+2,\ldots,A_{i+1}-1 between A_i and A_{i+1}.
    • If A_i > A_{i+1}, insert A_i-1,A_i-2,\ldots,A_{i+1}+1 between A_i and A_{i+1}.
  3. Return to step 1.

Print the sequence when the procedure ends.

Constraints

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 100
  • A_i \neq A_{i+1}
  • 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 the terms in the sequence when the procedure ends, separated by spaces.


Sample Input 1

4
2 5 1 2

Sample Output 1

2 3 4 5 4 3 2 1 2

The initial sequence is (2,5,1,2). The procedure goes as follows.

  • Insert 3,4 between the first term 2 and the second term 5, making the sequence (2,3,4,5,1,2).
  • Insert 4,3,2 between the fourth term 5 and the fifth term 1, making the sequence (2,3,4,5,4,3,2,1,2).

Sample Input 2

6
3 4 5 6 5 4

Sample Output 2

3 4 5 6 5 4

No insertions may be performed.

E - Adjacent Swaps

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

N 個のボールが左右一列に並んでいます。初め、左から i \, (1 \leq i \leq N) 番目のボールには整数 i が書かれています。

高橋君は Q 回の操作を行いました。 i \, (1 \leq i \leq Q) 回目に行われた操作は次のようなものです。

  • 整数 x_i が書かれているボールをその右隣のボールと入れ替える。ただし、整数 x_i が書かれているボールが元々右端にあった場合、代わりに左隣のボールと入れ替える。

操作後において左から i \, (1 \leq i \leq N) 番目のボールに書かれている整数を a_i とします。 a_1,\ldots,a_N を求めてください。

制約

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

入力

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

N Q
x_1
\vdots
x_Q

出力

a_1,\ldots,a_N を空白区切りで出力せよ。


入力例 1

5 5
1
2
3
4
5

出力例 1

1 2 3 5 4

操作は以下のように行われます。

  • 1 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 2,1,3,4,5 となる。
  • 2 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,4,5 となる。
  • 3 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,4,3,5 となる。
  • 4 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,4,5 となる。
  • 5 と書かれたボールは右端にあるので左隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,5,4 となる。

入力例 2

7 7
7
7
7
7
7
7
7

出力例 2

1 2 3 4 5 7 6

入力例 3

10 6
1
5
2
9
6
6

出力例 3

1 2 3 4 5 7 6 8 10 9

Score : 300 points

Problem Statement

N balls are lined up in a row from left to right. Initially, the i-th (1 \leq i \leq N) ball from the left has an integer i written on it.

Takahashi has performed Q operations. The i-th (1 \leq i \leq Q) operation was as follows.

  • Swap the ball with the integer x_i written on it with the next ball to the right. If the ball with the integer x_i written on it was originally the rightmost ball, swap it with the next ball to the left instead.

Let a_i be the integer written on the i-th (1 \leq i \leq N) ball after the operations. Find a_1,\ldots,a_N.

Constraints

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

Input

Input is given from Standard Input in the following format:

N Q
x_1
\vdots
x_Q

Output

Print a_1,\ldots,a_N, with spaces in between.


Sample Input 1

5 5
1
2
3
4
5

Sample Output 1

1 2 3 5 4

The operations are performed as follows.

  • Swap the ball with 1 written on it with the next ball to the right. Now, the balls have integers 2,1,3,4,5 written on them, from left to right.
  • Swap the ball with 2 written on it with the next ball to the right. Now, the balls have integers 1,2,3,4,5 written on them, from left to right.
  • Swap the ball with 3 written on it with the next ball to the right. Now, the balls have integers 1,2,4,3,5 written on them, from left to right.
  • Swap the ball with 4 written on it with the next ball to the right. Now, the balls have integers 1,2,3,4,5 written on them, from left to right.
  • Swap the ball with 5 written on it with the next ball to the left, since it is the rightmost ball. Now, the balls have integers 1,2,3,5,4 written on them, from left to right.

Sample Input 2

7 7
7
7
7
7
7
7
7

Sample Output 2

1 2 3 4 5 7 6

Sample Input 3

10 6
1
5
2
9
6
6

Sample Output 3

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

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

N 行、横 N 列のマス目があり、上から i 行目、左から j 列目のマスには整数 N\times (i-1)+j が書かれています。

今から T ターンにわたって相異なる整数が宣言されます。i ターン目には A_i が宣言され、A_i が書かれたマスに印をつけます。初めてビンゴを達成するのは何ターン目か求めてください。ただし、T ターンの中でビンゴを達成しない場合は -1 を出力してください。

ここで、ビンゴを達成するとは以下のいずれかのうち少なくとも一つ満たされることを言います。

  • マス目の横の列であって、列に含まれる N 個のマスすべてに印がついているものが存在する
  • マス目の縦の列であって、列に含まれる N 個のマスすべてに印がついているものが存在する
  • マス目の対角線の列であって、列に含まれる N 個のマスすべてに印がついているものが存在する

制約

  • 2\leq N\leq 2\times 10^3
  • 1\leq T\leq \min(N^2,2\times 10^5)
  • 1\leq A_i\leq N^2
  • i\neq j ならば A_i\neq A_j
  • 入力は全て整数

入力

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

N T
A_1 A_2 \ldots A_T

出力

T ターンの中でビンゴを達成するならば初めてビンゴを達成するターンを、そうでないならば -1 を出力せよ。


入力例 1

3 5
5 1 8 9 7

出力例 1

4

マス目の状態は以下のように変化します。初めてビンゴを達成するのは 4 ターン目です。


入力例 2

3 5
4 2 9 7 5

出力例 2

-1

5 ターンの中でビンゴを達成できないので -1 を出力してください。


入力例 3

4 12
13 9 6 5 2 7 16 14 8 3 10 11

出力例 3

9

Score : 300 points

Problem Statement

There is an N \times N grid, where the cell at the i-th row from the top and the j-th column from the left contains the integer N \times (i-1) + j.

Over T turns, integers will be announced. On Turn i, the integer A_i is announced, and the cell containing A_i is marked. Determine the turn on which Bingo is achieved for the first time. If Bingo is not achieved within T turns, print -1.

Here, achieving Bingo means satisfying at least one of the following conditions:

  • There exists a row in which all N cells are marked.
  • There exists a column in which all N cells are marked.
  • There exists a diagonal line (from top-left to bottom-right or from top-right to bottom-left) in which all N cells are marked.

Constraints

  • 2 \leq N \leq 2 \times 10^3
  • 1 \leq T \leq \min(N^2, 2 \times 10^5)
  • 1 \leq A_i \leq N^2
  • A_i \neq A_j if i \neq j.
  • All input values are integers.

Input

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

N T
A_1 A_2 \ldots A_T

Output

If Bingo is achieved within T turns, print the turn number on which Bingo is achieved for the first time; otherwise, print -1.


Sample Input 1

3 5
5 1 8 9 7

Sample Output 1

4

The state of the grid changes as follows. Bingo is achieved for the first time on Turn 4.


Sample Input 2

3 5
4 2 9 7 5

Sample Output 2

-1

Bingo is not achieved within five turns, so print -1.


Sample Input 3

4 12
13 9 6 5 2 7 16 14 8 3 10 11

Sample Output 3

9
G - ±1 Operation 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

長さ N の数列 A=(A_1,A_2,\dots,A_N) が与えられます。この A に以下を施すことを「操作」と呼びます。

  • まず、 1 \le i \le N を満たす整数 i を選択する。
  • 次に、以下の 2 つのうちどちらかを選択し、実行する。
    • A_i1 を加算する。
    • A_i から 1 を減算する。

Q 個の質問に答えてください。
i 個目の質問は以下です。

  • 「操作」を 0 回以上何度でも使って A の要素を全て X_i にする時、必要な「操作」の最小回数を求めてください。

制約

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

入力

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

N Q
A_1 A_2 \dots A_N
X_1
X_2
\vdots
X_Q

出力

Q 行にわたって出力せよ。
出力のうち i 行目には、 i 個目の質問に対する答えを整数として出力せよ。


入力例 1

5 3
6 11 2 5 5
5
20
0

出力例 1

10
71
29

A=(6,11,2,5,5) であり、この入力には 3 つの質問が含まれます。

1 つ目の質問について、 A に以下のように 10 回の「操作」を施すことで、 A の要素を全て 5 にすることができます。

  • A_1 から 1 減算する。
  • A_2 から 1 減算することを 6 度繰り返す。
  • A_31 加算することを 3 度繰り返す。

9 回以下の「操作」で A の要素を全て 5 にすることはできません。

2 つ目の質問について、 A71 回の「操作」を施すことで、 A の要素を全て 20 にすることができます。

3 つ目の質問について、 A29 回の「操作」を施すことで、 A の要素を全て 0 にすることができます。


入力例 2

10 5
1000000000 314159265 271828182 141421356 161803398 0 777777777 255255255 536870912 998244353
555555555
321654987
1000000000
789456123
0

出力例 2

3316905982
2811735560
5542639502
4275864946
4457360498

出力が 32bit 整数に収まらない場合もあります。

Score : 400 points

Problem Statement

You are given a sequence of length N: A=(A_1,A_2,\dots,A_N). The following action on this sequence is called an operation.

  • First, choose an integer i such that 1 \le i \le N.
  • Next, choose and do one of the following.
    • Add 1 to A_i.
    • Subtract 1 from A_i.

Answer Q questions.
The i-th question is the following.

  • Consider performing zero or more operations to change every element of A to X_i. Find the minimum number of operations required to do so.

Constraints

  • All values in input are integers.
  • 1 \le N,Q \le 2 \times 10^5
  • 0 \le A_i \le 10^9
  • 0 \le X_i \le 10^9

Input

Input is given from Standard Input in the following format:

N Q
A_1 A_2 \dots A_N
X_1
X_2
\vdots
X_Q

Output

Print Q lines.
The i-th line should contain the answer to the i-th question as an integer.


Sample Input 1

5 3
6 11 2 5 5
5
20
0

Sample Output 1

10
71
29

We have A=(6,11,2,5,5) and three questions in this input.

For the 1-st question, you can change every element of A to 5 in 10 operations as follows.

  • Subtract 1 from A_1.
  • Subtract 1 from A_2 six times.
  • Add 1 to A_3 three times.

It is impossible to change every element of A to 5 in 9 or fewer operations.

For the 2-nd question, you can change every element of A to 20 in 71 operations.

For the 3-rd question, you can change every element of A to 0 in 29 operations.


Sample Input 2

10 5
1000000000 314159265 271828182 141421356 161803398 0 777777777 255255255 536870912 998244353
555555555
321654987
1000000000
789456123
0

Sample Output 2

3316905982
2811735560
5542639502
4275864946
4457360498

The output may not fit into 32-bit integers.

H - At Least One

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

整数 M および N 個の整数の組 (A_1, B_1), (A_2, B_2), \dots, (A_N, B_N) が与えられます。
すべての i について 1 \leq A_i \lt B_i \leq M が成り立っています。

次の条件を満たす数列 S良い数列と呼びます。

  • S は数列 (1,2,3,..., M) の連続部分列である。
  • すべての i について SA_i, B_i の少なくとも一方を含んでいる。

長さ k の良い数列としてあり得るものの個数を f(k) とします。
f(1), f(2), \dots, f(M) を列挙してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 2 \leq M \leq 2 \times 10^5
  • 1 \leq A_i \lt B_i \leq M
  • 入力される値はすべて整数

入力

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

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

出力

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

f(1) f(2) \dots f(M)

入力例 1

3 5
1 3
1 4
2 5

出力例 1

0 1 3 2 1

良い数列としてあり得るものを列挙すると次のようになります。

  • (1,2)
  • (1,2,3)
  • (2,3,4)
  • (3,4,5)
  • (1,2,3,4)
  • (2,3,4,5)
  • (1,2,3,4,5)

入力例 2

1 2
1 2

出力例 2

2 1

入力例 3

5 9
1 5
1 7
5 6
5 8
2 6

出力例 3

0 0 1 2 4 4 3 2 1

Score : 500 points

Problem Statement

You are given an integer M and N pairs of integers (A_1, B_1), (A_2, B_2), \dots, (A_N, B_N).
For all i, it holds that 1 \leq A_i \lt B_i \leq M.

A sequence S is said to be a good sequence if the following conditions are satisfied:

  • S is a contiguous subsequence of the sequence (1,2,3,..., M).
  • For all i, S contains at least one of A_i and B_i.

Let f(k) be the number of possible good sequences of length k.
Enumerate f(1), f(2), \dots, f(M).

Constraints

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

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print the answers in the following format:

f(1) f(2) \dots f(M)

Sample Input 1

3 5
1 3
1 4
2 5

Sample Output 1

0 1 3 2 1

Here is the list of all possible good sequences.

  • (1,2)
  • (1,2,3)
  • (2,3,4)
  • (3,4,5)
  • (1,2,3,4)
  • (2,3,4,5)
  • (1,2,3,4,5)

Sample Input 2

1 2
1 2

Sample Output 2

2 1

Sample Input 3

5 9
1 5
1 7
5 6
5 8
2 6

Sample Output 3

0 0 1 2 4 4 3 2 1
I - Lottery

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

高橋君はくじを引こうとしています。

くじを 1 回引くごとに、N 種類の賞品のいずれかが手に入ります。賞品 i が手に入る確率は \frac{W_i}{\sum_{j=1}^{N}W_j} であり、各くじの結果は独立です。

くじを K 回引いたとき、ちょうど M 種類の賞品が手に入る確率はいくらでしょうか? \bmod 998244353 で求めてください。

注記

有理数を出力する際は、まずその有理数を分数 \frac{y}{x} として表してください。 ここで、x,y は整数であり、x998244353 で割り切れてはなりません(この問題の制約下で、そのような表現は必ず可能です)。 そして、xz\equiv y \pmod{998244353} を満たすような 0 以上 998244352 以下の唯一の整数 z を出力してください。

制約

  • 1 \leq K \leq 50
  • 1 \leq M \leq N \leq 50
  • 0 < W_i
  • 0 < W_1 + \ldots + W_N < 998244353
  • 入力は全て整数である

入力

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

N M K
W_1
\vdots
W_N

出力

答えを出力せよ。


入力例 1

2 1 2
2
1

出力例 1

221832079

各くじの結果として、賞品 1 が手に入る確率が \frac{2}{3}、賞品 2 が手に入る確率が \frac{1}{3} です。

2 回のくじの結果として、ともに賞品 1 を手に入れる確率が \frac{4}{9}、ともに賞品 2 を手に入れる確率が \frac{1}{9} であるため、求める答えは \frac{5}{9} です。

これを注記にしたがって \bmod 998244353 で出力すると 221832079 になります。


入力例 2

3 3 2
1
1
1

出力例 2

0

くじを 2 回引いて 3 種類の賞品を手に入れることはできません。したがって求める確率は 0 です。


入力例 3

3 3 10
499122176
499122175
1

出力例 3

335346748

入力例 4

10 8 15
1
1
1
1
1
1
1
1
1
1

出力例 4

755239064

Score : 500 points

Problem Statement

Takahashi is participating in a lottery.

Each time he takes a draw, he gets one of the N prizes available. Prize i is awarded with probability \frac{W_i}{\sum_{j=1}^{N}W_j}. The results of the draws are independent of each other.

What is the probability that he gets exactly M different prizes from K draws? Find it modulo 998244353.

Note

To print a rational number, start by representing it as a fraction \frac{y}{x}. Here, x and y should be integers, and x should not be divisible by 998244353 (under the Constraints of this problem, such a representation is always possible). Then, print the only integer z between 0 and 998244352 (inclusive) such that xz\equiv y \pmod{998244353}.

Constraints

  • 1 \leq K \leq 50
  • 1 \leq M \leq N \leq 50
  • 0 < W_i
  • 0 < W_1 + \ldots + W_N < 998244353
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
W_1
\vdots
W_N

Output

Print the answer.


Sample Input 1

2 1 2
2
1

Sample Output 1

221832079

Each draw awards Prize 1 with probability \frac{2}{3} and Prize 2 with probability \frac{1}{3}.

He gets Prize 1 at both of the two draws with probability \frac{4}{9}, and Prize 2 at both draws with probability \frac{1}{9}, so the sought probability is \frac{5}{9}.

The modulo 998244353 representation of this value, according to Note, is 221832079.


Sample Input 2

3 3 2
1
1
1

Sample Output 2

0

It is impossible to get three different prizes from two draws, so the sought probability is 0.


Sample Input 3

3 3 10
499122176
499122175
1

Sample Output 3

335346748

Sample Input 4

10 8 15
1
1
1
1
1
1
1
1
1
1

Sample Output 4

755239064