A - Three Threes

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

配点 : 100 点

問題文

1 以上 9 以下の整数 N が入力として与えられます。

数字 N を N 個繋げて得られる文字列を出力してください。

制約

  • N は 1 以上 9 以下の整数

入力

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

N

出力

答えを出力せよ。


入力例 1

3

出力例 1

333

3 を 3 個繋げて得られる文字列は 333 です。


入力例 2

9

出力例 2

999999999

Score : 100 points

Problem Statement

You are given an integer N between 1 and 9, inclusive, as input.

Concatenate N copies of the digit N and print the resulting string.

Constraints

  • N is an integer between 1 and 9, inclusive.

Input

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

N

Output

Print the answer.


Sample Input 1

3

Sample Output 1

333

Concatenate three copies of the digit 3 to yield the string 333.


Sample Input 2

9

Sample Output 2

999999999
B - Stage Clear

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

配点 : 100 点

問題文

高橋くんはゲームで遊んでいます。 このゲームにはワールドが 8 つあり、それぞれのワールドにはステージが 8 つずつあります。 ステージには順番があり、最初のステージは 1 個めのワールドにある 1 個めのステージです。 i 個め (1\le i\le 8) のワールドにある j 個め (1\le j\le 8) のステージの次のステージは、以下のようになっています。

  • j\lt8 のとき、次のステージは i 個めのワールドにある j+1 個めのステージです。
  • i\lt8,j=8 のとき、次のステージは i+1 個めのワールドにある 1 個めのステージです。
  • i=8,j=8 のとき、次のステージはありません。このステージが最後のステージです。

i 個め (1\le i\le 8) のワールドにある j 個め (1\le j\le 8) のステージの名前は i-j です。 たとえば、最初のステージ名は 1-1 で、最後のステージ名は 8-8 です。

高橋くんが現在遊んでいるステージのステージ名 S が与えられるので、次のステージのステージ名を出力してください。

制約

  • S はいずれかのステージのステージ名である。
  • S は 8-8 ではない。

入力

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

S

出力

次のステージのステージ名を出力せよ。


入力例 1

4-2

出力例 1

4-3

4 個めのワールドの 2 個めのステージの次のステージは、同じワールドの 3 個めのステージです。


入力例 2

1-8

出力例 2

2-1

1-8 は 1 個めのワールドの最後のステージなので、次のステージは 2 個めのワールドの 1 個めのステージです。


入力例 3

3-3

出力例 3

3-4

Score : 100 points

Problem Statement

Takahashi is playing a game. This game has eight worlds, and each world has eight stages. The stages have an order, and the first stage is the 1st stage in the 1st world. The next stage after the j-th stage (1\le j\le 8) in the i-th world (1\le i\le 8) is as follows:

  • When j\lt8, the next stage is the (j+1)-th stage in the i-th world.
  • When i\lt8,j=8, the next stage is the 1st stage in the (i+1)-th world.
  • When i=8,j=8, there is no next stage. This stage is the last stage.

The name of the j-th stage (1\le j\le 8) in the i-th world (1\le i\le 8) is i-j. For example, the name of the first stage is 1-1, and the name of the last stage is 8-8.

Given the stage name S of the stage Takahashi is currently playing, output the stage name of the next stage.

Constraints

  • S is the stage name of one of the stages.
  • S is not 8-8.

Input

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

S

Output

Output the stage name of the next stage.


Sample Input 1

4-2

Sample Output 1

4-3

The next stage after the 2nd stage in the 4th world is the 3rd stage in the same world.


Sample Input 2

1-8

Sample Output 2

2-1

1-8 is the last stage in the 1st world, so the next stage is the 1st stage in the 2nd world.


Sample Input 3

3-3

Sample Output 3

3-4
C - Bird Watching

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

配点 : 200 点

問題文

空に M 種類の鳥が合わせて N 羽飛んでいます。
鳥の種類には 1,2,\dots,M の番号が付けられています。
N 羽の鳥には 1,2,\dots,N の番号が付けられており、鳥 i の種類は A_i で、大きさは B_i です。

全ての k=1,2,\dots,M について、飛んでいる種類 k の鳥の大きさの平均値を求めてください。
ただし、全ての k=1,2,\dots,M について、種類 k の鳥が 1 羽以上飛んでいることが保証されます。

制約

  • 1 \le M \le N \le 100
  • 1 \le A_i \le M
  • 1 \le B_i \le 100
  • 種類 k の鳥が少なくとも 1 羽存在する ( 1 \le k \le M )
  • 入力される値は全て整数

入力

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

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

出力

M 行出力せよ。
k ( 1 \le k \le M ) 行目には、種類 k の鳥の大きさの平均値を出力せよ。
真の解との絶対誤差または相対誤差が 10^{-5} 以下であるとき、正解とみなされる。


入力例 1

10 5
4 92
1 16
3 77
4 99
2 89
3 8
1 40
5 56
1 40
4 77

出力例 1

32.00000000000000000000
89.00000000000000000000
42.50000000000000000000
89.33333333333333333333
56.00000000000000000000
  • 種類 1 の鳥の大きさの平均値は (16+40+40)/3 = 32 です。
  • 種類 2 の鳥の大きさの平均値は 89 です。
  • 種類 3 の鳥の大きさの平均値は (77+8)/2 = 42.5 です。
  • 種類 4 の鳥の大きさの平均値は (92+99+77)/3 \approx 89.3333 です。
  • 種類 5 の鳥の大きさの平均値は 56 です。

Score : 200 points

Problem Statement

There are N birds of M types flying in the sky.
The bird types are numbered 1,2,\dots,M.
The N birds are numbered 1,2,\dots,N, and bird i is of type A_i and has size B_i.

For every k=1,2,\dots,M, find the average size of the flying birds of type k.
It is guaranteed that for every k=1,2,\dots,M, there is at least one bird of type k flying.

Constraints

  • 1 \le M \le N \le 100
  • 1 \le A_i \le M
  • 1 \le B_i \le 100
  • There exists at least one bird of type k ( 1 \le k \le M ).
  • All input values are integers.

Input

The 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

Output M lines.
The k-th line ( 1 \le k \le M ) should contain the average size of birds of type k.
Your answer will be considered correct if the absolute or relative error from the true value is at most 10^{-5}.


Sample Input 1

10 5
4 92
1 16
3 77
4 99
2 89
3 8
1 40
5 56
1 40
4 77

Sample Output 1

32.00000000000000000000
89.00000000000000000000
42.50000000000000000000
89.33333333333333333333
56.00000000000000000000
  • The average size of birds of type 1 is (16+40+40)/3 = 32.
  • The average size of birds of type 2 is 89.
  • The average size of birds of type 3 is (77+8)/2 = 42.5.
  • The average size of birds of type 4 is (92+99+77)/3 \approx 89.3333.
  • The average size of birds of type 5 is 56.
D - Japanese Cursed Doll

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

配点 : 200 点

問題文

N 人の人がおり、i 人目 (1\leq i\leq N) の現在の髪の長さは L_i です。
すべての人は 1 日経つごとに髪の長さが 1 ずつ増えます。

髪の長さが T 以上の人が初めて P 人以上になるのは現在から何日後か出力してください。
ただし、現在の時点ですでに髪の長さが T 以上の人が P 人以上にいる場合は 0 を出力してください。

制約

  • 1\leq N\leq 100
  • 1\leq L_i\leq 100
  • 1\leq T\leq 100
  • 1\leq P\leq N
  • 入力はすべて整数

入力

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

N T P
L_1 L_2 \ldots L_N

出力

髪の長さが T 以上の人が初めて P 人以上になるのは現在から何日後か出力せよ。 ただし、現在の時点ですでに条件をみたしている場合は 0 を出力せよ。


入力例 1

5 10 3
3 11 1 6 2

出力例 1

7

5 人の人がおり、現在の時点で髪の長さはそれぞれ 3,11,1,6,2 であるため、髪の長さが 10 以上の人は 1 人です。

現在から 7 日後にはそれぞれの人の髪の長さは順に 10,18,8,13,9 となり、髪の長さが 10 以上の人は 3 人となります。
現在から 6 日後の時点では髪の長さが 10 以上の人は 2 人であるため条件をみたしておらず、よって 7 を出力します。


入力例 2

2 5 2
10 10

出力例 2

0

現在の時点ですでに髪の長さが 5 以上の人が 2 人いるため条件をみたしており、0 を出力します。


入力例 3

3 10 1
1 2 3

出力例 3

7

Score : 200 points

Problem Statement

There are N people, and the current hair length of the i-th person (1 \leq i \leq N) is L_i.
Each person's hair grows by 1 per day.

Print the number of days after which the number of people whose hair length is at least T becomes P or more for the first time.
If there are already P or more people whose hair length is at least T now, print 0.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq L_i \leq 100
  • 1 \leq T \leq 100
  • 1 \leq P \leq N
  • All input values are integers.

Input

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

N T P
L_1 L_2 \ldots L_N

Output

Print the number of days after which the number of people whose hair length is at least T becomes P or more for the first time. If this condition is already satisfied now, print 0.


Sample Input 1

5 10 3
3 11 1 6 2

Sample Output 1

7

There are five people, and their current hair lengths are 3, 11, 1, 6, 2, so there is one person whose hair length is at least 10.

After seven days, the hair lengths of the people will be 10, 18, 8, 13, 9, respectively, and there will be three people whose hair length is at least 10.
After six days, there are only two people whose hair length is at least 10, not satisfying the condition, so print 7.


Sample Input 2

2 5 2
10 10

Sample Output 2

0

Since there are already two people whose hair length is at least 5 now, satisfying the condition, so print 0.


Sample Input 3

3 10 1
1 2 3

Sample Output 3

7
E - Many Balls

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

配点 : 300 点

問題文

空の箱があります。
髙橋君は以下の 2 種類の魔法を好きな順番で好きな回数使えます。

  • 魔法 A :箱の中にボールを 1 つ増やす
  • 魔法 B :箱の中のボールの数を 2 倍にする

合計 \mathbf{120} 回以内の魔法で、箱の中のボールの数をちょうど N 個にする方法を 1 つ教えてください。
なお、与えられた制約のもとで条件を満たす方法が必ず存在することが示せます。

魔法以外の方法でボールの数を変化させることはできません。

制約

  • 1 \leq N \leq 10^{18}
  • 入力は全て整数

入力

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

N

出力

A , B のみからなる文字列 S を出力せよ。
S の i 文字目が A ならば、髙橋君が i 回目に使う魔法が魔法 A であることを表し、B ならば魔法 B であることを表す。

S の長さは \mathbf{120} 以下でなければならない。


入力例 1

5

出力例 1

AABA

ボールの数は、0 \xrightarrow{A} 1\xrightarrow{A} 2 \xrightarrow{B}4\xrightarrow{A} 5 と変化します。
AAAAA などの答えも正解になります。


入力例 2

14

出力例 2

BBABBAAAB

ボールの数は、0 \xrightarrow{B} 0 \xrightarrow{B} 0 \xrightarrow{A}1 \xrightarrow{B} 2 \xrightarrow{B} 4 \xrightarrow{A}5 \xrightarrow{A}6 \xrightarrow{A} 7 \xrightarrow{B}14 と変化します。
S の長さを最小化する必要はありません。

Score : 300 points

Problem Statement

We have an empty box.
Takahashi can cast the following two spells any number of times in any order.

  • Spell A: puts one new ball into the box.
  • Spell B: doubles the number of balls in the box.

Tell us a way to have exactly N balls in the box with at most \mathbf{120} casts of spells.
It can be proved that there always exists such a way under the Constraints given.

There is no way other than spells to alter the number of balls in the box.

Constraints

  • 1 \leq N \leq 10^{18}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print a string S consisting of A and B. The i-th character of S should represent the spell for the i-th cast.

S must have at most \mathbf{120} characters.


Sample Input 1

5

Sample Output 1

AABA

This changes the number of balls as follows: 0 \xrightarrow{A} 1\xrightarrow{A} 2 \xrightarrow{B}4\xrightarrow{A} 5.
There are also other acceptable outputs, such as AAAAA.


Sample Input 2

14

Sample Output 2

BBABBAAAB

This changes the number of balls as follows: 0 \xrightarrow{B} 0 \xrightarrow{B} 0 \xrightarrow{A}1 \xrightarrow{B} 2 \xrightarrow{B} 4 \xrightarrow{A}5 \xrightarrow{A}6 \xrightarrow{A} 7 \xrightarrow{B}14.
It is not required to minimize the length of S.

F - Minimize Abs 2

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

配点 : 300 点

問題文

正整数 D が与えられます。

非負整数 x,y に対する |x^2+y^2-D| の最小値を求めてください。

制約

  • 1\leq D \leq 2\times 10^{12}
  • 入力は全て整数

入力

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

D

出力

答えを出力せよ。


入力例 1

21

出力例 1

1

x=4,y=2 のとき |x^2+y^2-D| = |16+4-21|=1 となります。

|x^2+y^2-D|=0 を満たすような非負整数 x,y は存在しないので、答えは 1 です。


入力例 2

998244353

出力例 2

0

入力例 3

264428617

出力例 3

32

Score : 300 points

Problem Statement

You are given a positive integer D.

Find the minimum value of |x^2+y^2-D| for non-negative integers x and y.

Constraints

  • 1\leq D \leq 2\times 10^{12}
  • All input values are integers.

Input

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

D

Output

Print the answer.


Sample Input 1

21

Sample Output 1

1

For x=4 and y=2, we have |x^2+y^2-D| = |16+4-21|=1.

There are no non-negative integers x and y such that |x^2+y^2-D|=0, so the answer is 1.


Sample Input 2

998244353

Sample Output 2

0

Sample Input 3

264428617

Sample Output 3

32
G - Tile Pattern

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

配点 : 450 点

問題文

縦横 10^9 マスのグリッドがあります。上から i + 1 行目、左から j + 1 列目 (0 \leq i, j \lt 10^9) にあるマスを (i, j) と呼びます。(通常と異なる index の割り当て方に注意してください。)
各マスは黒マスか白マスのいずれかです。マス (i, j) の色は文字 P[i \bmod N][j \bmod N] によって表されて、B ならばマス (i, j) は黒マス、W ならば白マスです。ここで a \bmod b は a を b で割った余りを意味します。

Q 個のクエリが与えられるので順に処理してください。
各クエリでは 4 つの整数 A, B, C, D が与えられるので、(A, B) を左上隅、(C, D) を右下隅とする長方形領域に含まれる黒マスの個数を求めてください。

制約

  • 1 \leq N \leq 1000
  • P[i][j] は W または B
  • 1 \leq Q \leq 2 \times 10^5
  • 0 \leq A \leq C \lt 10^9
  • 0 \leq B \leq D \lt 10^9
  • N, Q, A, B, C, D は全て整数

入力

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

N Q
P[0][0]P[0][1]\dots P[0][N-1]
P[1][0]P[1][1]\dots P[1][N-1]
\vdots
P[N-1][0]P[N-1][1]\dots P[N-1][N-1]
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q

各クエリは以下の形式で与えられる。

A B C D

出力

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


入力例 1

3 2
WWB
BBW
WBW
1 2 3 4
0 3 4 5

出力例 1

4
7

グリッドの左上部分を図示すると次の図のようになります。

image

1 番目のクエリについて、(1, 2) を左上隅、(3, 4) を右下隅とする長方形領域は図の赤い枠線に囲まれた部分で、領域に含まれる黒マスの個数は 4 個です。
2 番目のクエリについて、(0, 3) を左上隅、(4, 5) を右下隅とする長方形領域は図の青い枠線に囲まれた部分で、領域に含まれる黒マスの個数は 7 個です。


入力例 2

10 5
BBBWWWBBBW
WWWWWBBBWB
BBBWBBWBBB
BBBWWBWWWW
WWWWBWBWBW
WBBWBWBBBB
WWBBBWWBWB
WBWBWWBBBB
WBWBWBBWWW
WWWBWWBWWB
5 21 21 93
35 35 70 43
55 72 61 84
36 33 46 95
0 0 999999999 999999999

出力例 2

621
167
44
344
500000000000000000

Score : 450 points

Problem Statement

There is a grid with 10^9 by 10^9 squares. Let (i, j) denote the square at the (i + 1)-th row from the top and the (j + 1)-th column from the left (0 \leq i, j \lt 10^9). (Note the unusual index assignment.)
Each square is black or white. The color of the square (i, j) is represented by a character P[i \bmod N][j \bmod N], where B means black, and W means white. Here, a \bmod b denotes the remainder when a is divided by b.

Answer Q queries.
Each query gives you four integers A, B, C, D and asks you to find the number of black squares contained in the rectangular area with (A, B) as the top-left corner and (C, D) as the bottom-right corner.

Constraints

  • 1 \leq N \leq 1000
  • P[i][j] is W or B.
  • 1 \leq Q \leq 2 \times 10^5
  • 0 \leq A \leq C \lt 10^9
  • 0 \leq B \leq D \lt 10^9
  • N, Q, A, B, C, D are all integers.

Input

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

N Q
P[0][0]P[0][1]\dots P[0][N-1]
P[1][0]P[1][1]\dots P[1][N-1]
\vdots
P[N-1][0]P[N-1][1]\dots P[N-1][N-1]
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q

Each query is given in the following format:

A B C D

Output

Follow the instructions in the problem statement and print the answers to the queries, separated by newlines.


Sample Input 1

3 2
WWB
BBW
WBW
1 2 3 4
0 3 4 5

Sample Output 1

4
7

The figure below illustrates the upper left part of the grid.

image

For the first query, the rectangular area with (1, 2) as the top-left corner and (3, 4) as the bottom-right corner, surrounded by the red frame in the figure, contains four black squares.
For the second query, the rectangular area with (0, 3) as the top-left corner and (4, 5) as the bottom-right corner, surrounded by the blue frame in the figure, contains seven black squares.


Sample Input 2

10 5
BBBWWWBBBW
WWWWWBBBWB
BBBWBBWBBB
BBBWWBWWWW
WWWWBWBWBW
WBBWBWBBBB
WWBBBWWBWB
WBWBWWBBBB
WBWBWBBWWW
WWWBWWBWWB
5 21 21 93
35 35 70 43
55 72 61 84
36 33 46 95
0 0 999999999 999999999

Sample Output 2

621
167
44
344
500000000000000000
H - AtCoder Hotel

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

配点 : {500} 点

問題文

高橋くん一行は、AtCoder Land に行くためにランド内にあるホテルに泊まることにしました。

N 人の人と M 個のランクが付いた部屋があります。

i 番目の人はランクが A_i 以上の部屋に泊まりたいと考えています。

また、i 番目の部屋のランクは R_i、定員は B_i 人、客室料金は C_i 円です。 C_i 円払うことで、B_i 人以下であれば何人でも i 番目の部屋に泊まることができます。

N 人全員が部屋に泊まることが可能か判定し、可能な場合必要な金額の総和の最小値を求めてください。

制約

  • 1\leq N,M \leq 5000
  • 1\leq A_i,R_i,B_i,C_i \leq 5000
  • 入力は全て整数

入力

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

N M
A_1 \ldots A_N
R_1 B_1 C_1
\vdots
R_M B_M C_M

出力

N 人全員が部屋に泊まることが可能な場合、必要な金額の総和の最小値を X 円とする。このとき X を出力せよ。

不可能な場合 -1 を出力せよ。


入力例 1

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

出力例 1

4

1 番目の人が 2 番目の部屋に泊まり、それ以外の人が 1 番目の部屋に泊まることを考えます。

このとき必要な金額の総和は 4 となり、これが最小であることが示せます。


入力例 2

8 5
2 5 1 5 2 1 2 4
4 2 5
7 2 4
7 4 2
1 4 7
3 3 8

出力例 2

11

入力例 3

10 1
1 1 1 1 1 1 1 1 1 1
10 4 1

出力例 3

-1

N 人全員が部屋に泊まることはできません。

I - Lottery

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

配点 : 500 点

問題文

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

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

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

注記

有理数を出力する際は、まずその有理数を分数 \frac{y}{x} として表してください。 ここで、x,y は整数であり、x は 998244353 で割り切れてはなりません(この問題の制約下で、そのような表現は必ず可能です)。 そして、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