Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
正の整数 A,B が与えられます。
以下の値のうち少なくとも 1 つが 9 に等しい場合は Nine を、そうでない場合は Nein を出力してください。
- A + B
- A - B
- A \times B
- A \div B
制約
- 1 \leq A \leq 100
- 1 \leq B \leq 100
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
答えを出力せよ。
入力例 1
16 7
出力例 1
Nine
16 - 7 = 9 なので、Nine を出力します。
入力例 2
66 7
出力例 2
Nein
以下のどの値も 9 に等しくないので、Nein を出力します。
- 66 + 7 = 73
- 66 - 7 = 59
- 66 \times 7 = 462
- 66 \div 7 = \frac{66}{7}
入力例 3
9 1
出力例 3
Nine
入力例 4
9 9
出力例 4
Nein
Score : 100 points
Problem Statement
You are given positive integers A and B.
If at least one of the following values is equal to 9, output Nine; otherwise, output Nein.
- A + B
- A - B
- A \times B
- A \div B
Constraints
- 1 \leq A \leq 100
- 1 \leq B \leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Output the answer.
Sample Input 1
16 7
Sample Output 1
Nine
Since 16 - 7 = 9, output Nine.
Sample Input 2
66 7
Sample Output 2
Nein
None of the following values is equal to 9, so output Nein.
- 66 + 7 = 73
- 66 - 7 = 59
- 66 \times 7 = 462
- 66 \div 7 = \frac{66}{7}
Sample Input 3
9 1
Sample Output 3
Nine
Sample Input 4
9 9
Sample Output 4
Nein
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君はアンケート結果を集計しています。
アンケートには N 人が回答し、 i 人目の回答は英字からなる文字列 S_i です。
このアンケートにおいて、同じ回答をした人数の最大値を求めてください。
ただし、回答の大文字と小文字は区別しません。
例えば AtCoder, ATCODER, atcoder はいずれも同じ回答とみなします。
制約
- 1 \leq N \leq 100
- S_i は長さ 1 以上 10 以下の、英大文字及び英小文字のみからなる文字列
- N は整数である
入力
入力は以下の形式で標準入力から与えられる。
N S_1 \vdots S_N
出力
答えを出力せよ。
入力例 1
7 ARC abc ahc ABC beginner AbC ahc
出力例 1
3
ABC と同じ回答が 3 個あり、これが最大値です。
入力例 2
10 x x x x x x x x x x
出力例 2
10
Score : 200 points
Problem Statement
Takahashi is tallying the results of a survey.
N people answered the survey, and the i-th person's answer is a string S_i consisting of English letters.
Find the maximum number of people who gave the same answer in this survey.
Here, the case of the letters in the answers is not distinguished.
For example, AtCoder, ATCODER, and atcoder are all considered the same answer.
Constraints
- 1 \leq N \leq 100
- S_i is a string of length between 1 and 10 (inclusive) consisting of uppercase and lowercase English letters.
- N is an integer.
Input
The input is given from Standard Input in the following format:
N S_1 \vdots S_N
Output
Output the answer.
Sample Input 1
7 ARC abc ahc ABC beginner AbC ahc
Sample Output 1
3
There are three answers that are the same as ABC, and this number is the maximum.
Sample Input 2
10 x x x x x x x x x x
Sample Output 2
10
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
数直線上の N 箇所にクッキーが落ちています。i 番目のクッキーの落ちている座標は A_i です。
高橋君は最初、数直線の座標 0 にいて、N 個のクッキー全てを拾うまで以下の行動を繰り返します。
- 行動:自身から最も近いクッキーのある座標(複数あるときは座標の最も小さいもの)へ移動し、そのクッキーを拾う。
全てのクッキーを拾うまでの高橋君の移動距離の合計を求めてください。
制約
- 1 \leq N \leq 3\times 10^5
- -10^9 \leq A_i \leq 10^9
- A_i\neq 0
- A_i は相異なる
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \dots A_N
出力
答えを出力せよ。
入力例 1
4 -1 -4 2 -11
出力例 1
23
高橋君は以下のように行動します。
- 座標 0 から座標 -1 へ移動しクッキーを拾う。移動距離は 1 である。
- 座標 -1 から座標 -4 へ移動しクッキーを拾う。移動距離は 3 である。
- 座標 -4 から座標 2 へ移動しクッキーを拾う。移動距離は 6 である。
- 座標 2 から座標 -11 へ移動しクッキーを拾う。移動距離は 13 である。
よって、移動距離の合計は 1+3+6+13=23 となります。
2 回目の行動において、座標 -4 にあるクッキーと座標 2 にあるクッキーまでの距離はともに 3 ですが、高橋君は座標の小さい -4 の方へ移動します。
入力例 2
10 1 2 3 4 5 -1 -2 -3 -4 -6
出力例 2
17
Score : 300 points
Problem Statement
There are cookies at N positions on a number line. The coordinate of the i-th cookie is A_i.
Takahashi is initially at coordinate 0 on the number line, and repeats the following action until he has picked up all N cookies.
- Action: Move to the coordinate of the nearest cookie from his current position (if there are multiple such cookies, the one with the smallest coordinate), and pick up that cookie.
Find the total distance Takahashi travels until he picks up all the cookies.
Constraints
- 1 \leq N \leq 3\times 10^5
- -10^9 \leq A_i \leq 10^9
- A_i\neq 0
- The A_i are distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 \dots A_N
Output
Output the answer.
Sample Input 1
4 -1 -4 2 -11
Sample Output 1
23
Takahashi acts as follows.
- He moves from coordinate 0 to coordinate -1 and picks up the cookie. The distance traveled is 1.
- He moves from coordinate -1 to coordinate -4 and picks up the cookie. The distance traveled is 3.
- He moves from coordinate -4 to coordinate 2 and picks up the cookie. The distance traveled is 6.
- He moves from coordinate 2 to coordinate -11 and picks up the cookie. The distance traveled is 13.
Thus, the total distance traveled is 1+3+6+13=23.
In the second action, the distances to the cookie at coordinate -4 and the cookie at coordinate 2 are both 3, and Takahashi moves to -4, the smaller coordinate.
Sample Input 2
10 1 2 3 4 5 -1 -2 -3 -4 -6
Sample Output 2
17
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
無尽蔵の差込口をもつ充電器があります。時刻 0 にはどの差込口も空です。
バッテリーの最大容量は V です。バッテリーは差込口に挿入されているあいだ、残量が最大容量に達するまで速度 1 で充電されます(つまり、1 単位時間が経過するごとに残量が 1 増加します)。
Q 個のクエリを順に処理してください。q 番目のクエリは以下の形式で与えられます。なお、t_1 < \dots < t_Q が保証されます。
- タイプ 1 (1\ t_q\ w_q): 時刻 t_q に、残量 w_q のバッテリーを 1 つ差込口に挿入する。
- タイプ 2 (2\ t_q): 時刻 t_q に、最も残量が多いバッテリーを 1 つ差込口から排出し、そのバッテリーの残量を出力する。どの差込口にもバッテリーが無い場合は代わりに -1 を出力する。
制約
- 1 \leq Q \leq 3 \times 10^5
- 1 \leq V \leq 10^9
- タイプ 1 のクエリにおいて、1 \leq t_q \leq 10^9
- タイプ 1 のクエリにおいて、0 \leq w_q \leq V
- タイプ 2 のクエリにおいて、1 \leq t_q \leq 10^9
- t_1 < \dots < t_Q
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
Q V
\mathrm{query}_1
\vdots
\mathrm{query}_Q
ここで、\mathrm{query}_q は q 番目のクエリを表し、以下の 2 種類のいずれかの形式で与えられる。
1 t_q w_q
2 t_q
出力
タイプ 2 のクエリの個数を x として、x 行出力せよ。
k 行目 (1 \leq k \leq x) には、k 番目のタイプ 2 のクエリで出力するべき値を出力せよ。
入力例 1
7 100 1 15 60 1 25 80 2 30 1 45 0 2 60 2 70 2 80
出力例 1
85 100 25 -1
7 個のクエリを以下の順に処理します。
- 時刻 15 に、残量 60 のバッテリーを挿入する。この時点で、残量 60 のバッテリーが充電器にある。
- 時刻 25 に、残量 80 のバッテリーを挿入する。この時点で、残量 70, 80 のバッテリーが充電器にある。
- 時刻 30 の時点で、残量 75, 85 のバッテリーが充電器にある。このうち、残量 85 のバッテリーを排出する。
- 時刻 45 に、残量 0 のバッテリーを挿入する。この時点で、残量 0, 90 のバッテリーが充電器にある。
- 時刻 60 の時点で、残量 15, 100 のバッテリーが充電器にある。このうち、残量 100 のバッテリーを排出する。
- 時刻 70 の時点で、残量 25 のバッテリーが充電器にある。このうち、残量 25 のバッテリーを排出する。
- 時刻 80 の時点で、充電器に挿入されたバッテリーは無い。そのため、バッテリーの排出はしない。
入力例 2
20 380736236 1 21873985 256702097 2 86369729 1 114301317 288304981 1 147244640 305840435 2 150951976 1 331581391 50335458 1 352989552 47577202 1 400130024 345362760 2 458793150 2 509082216 1 591375600 197371572 1 617022014 101276068 1 679649471 310249627 1 796351653 268586022 1 825648347 129608152 2 908069704 2 921770319 1 949684819 372272469 1 971850999 335461408 2 986253026
出力例 2
321197841 324955640 380736236 380736236 380736236 380736236 380736236
Score : 400 points
Problem Statement
There is a charger with an unlimited number of charging slots. At time 0, all slots are empty.
The maximum capacity of a battery is V. While a battery is plugged into a slot, it is charged at a rate of 1 until its charge level reaches the maximum capacity (that is, the charge level increases by 1 for every 1 unit of time that passes).
Process Q queries in order. The q-th query is given in one of the following formats. Here, it is guaranteed that t_1 < \dots < t_Q.
- Type 1 (1\ t_q\ w_q): At time t_q, plug one battery with charge level w_q into a slot.
- Type 2 (2\ t_q): At time t_q, unplug one battery with the highest charge level from its slot, and output that battery's charge level. If there is no battery plugged into any slot, output -1 instead.
Constraints
- 1 \leq Q \leq 3 \times 10^5
- 1 \leq V \leq 10^9
- For type 1 queries, 1 \leq t_q \leq 10^9.
- For type 1 queries, 0 \leq w_q \leq V.
- For type 2 queries, 1 \leq t_q \leq 10^9.
- t_1 < \dots < t_Q
- The input values are all integers.
Input
The input is given from Standard Input in the following format:
Q V
\mathrm{query}_1
\vdots
\mathrm{query}_Q
Here, \mathrm{query}_q represents the q-th query, and is given in one of the following two formats:
1 t_q w_q
2 t_q
Output
Let x be the number of type 2 queries. Output x lines.
The k-th line (1 \leq k \leq x) should contain the value to be outputed for the k-th type 2 query.
Sample Input 1
7 100 1 15 60 1 25 80 2 30 1 45 0 2 60 2 70 2 80
Sample Output 1
85 100 25 -1
The seven queries are processed in the following order.
- At time 15, a battery with charge level 60 is plugged in. At this point, the charger has a battery with charge level 60.
- At time 25, a battery with charge level 80 is plugged in. At this point, the charger has batteries with charge levels 70, 80.
- At time 30, the charger has batteries with charge levels 75, 85. Of these, the battery with charge level 85 is unplugged.
- At time 45, a battery with charge level 0 is plugged in. At this point, the charger has batteries with charge levels 0, 90.
- At time 60, the charger has batteries with charge levels 15, 100. Of these, the battery with charge level 100 is unplugged.
- At time 70, the charger has a battery with charge level 25. This battery, with charge level 25, is unplugged.
- At time 80, no battery is plugged into the charger. Thus, no battery is unplugged.
Sample Input 2
20 380736236 1 21873985 256702097 2 86369729 1 114301317 288304981 1 147244640 305840435 2 150951976 1 331581391 50335458 1 352989552 47577202 1 400130024 345362760 2 458793150 2 509082216 1 591375600 197371572 1 617022014 101276068 1 679649471 310249627 1 796351653 268586022 1 825648347 129608152 2 908069704 2 921770319 1 949684819 372272469 1 971850999 335461408 2 986253026
Sample Output 2
321197841 324955640 380736236 380736236 380736236 380736236 380736236
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
1 から N の番号がついた N 個のボールがあります。ボール i には整数 A_i が書かれています。
N 個のボールからいくつかのボールを選ぶ方法に対して、選んだボールに書かれた数の和の 2 乗をその選び方のスコアと定めます。
N 個のボールから K 個を選ぶ方法 \binom{N}{K} 通り全てのスコアの総和を 998244353 で割った余りを求めてください。
制約
- 1 \leq K \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 \dots A_N
出力
答えを出力せよ。
入力例 1
3 2 1 10 100
出力例 1
22422
3 個のボールから 2 個を選ぶ方法は 3 通りあり、ボール 1,2 を選んだときスコアは (1+10)^2=121、ボール 1,3 を選んだときのスコアは (1+100)^2=10201、ボール 2,3 を選んだときのスコアは (10+100)^2=12100 となります。
求める答えはこれらの和で 121+10201+12100=22422 となります。
入力例 2
5 2 10 10 20 20 20
出力例 2
10600
複数のボールに同じ数が書かれていることもあります。
入力例 3
2 1 998244353 998244353
出力例 3
0
998244353 で割った余りを求めてください。
Score : 450 points
Problem Statement
There are N balls numbered 1 to N. Ball i has an integer A_i written on it.
For a way of choosing some balls from the N balls, define the score of that choice as the square of the sum of the numbers written on the chosen balls.
Find the sum, modulo 998244353, of the scores of all \binom{N}{K} ways of choosing K balls from the N balls.
Constraints
- 1 \leq K \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K A_1 \dots A_N
Output
Output the answer.
Sample Input 1
3 2 1 10 100
Sample Output 1
22422
There are three ways of choosing two balls from three balls: choosing balls 1,2 gives a score of (1+10)^2=121, choosing balls 1,3 gives a score of (1+100)^2=10201, and choosing balls 2,3 gives a score of (10+100)^2=12100.
The answer is the sum of these, 121+10201+12100=22422.
Sample Input 2
5 2 10 10 20 20 20
Sample Output 2
10600
Multiple balls may have the same number written on them.
Sample Input 3
2 1 998244353 998244353
Sample Output 3
0
Find the sum modulo 998244353.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
数字のみからなる N 個の文字列 S_1,\ldots,S_N が与えられます。
これらからちょうど K 個を選んで好きな順序で連結した文字列を、(先頭の余分なゼロを除いて)十進表記の整数として解釈したときの値として考えられる最大値を求めてください。
なお、全ての文字が 0 である文字列を、先頭の余分なゼロを除いて十進表記の整数として解釈したときの値は 0 であるとします。
制約
- 1 \leq K \leq N \leq 10^5
- S_i は数字のみからなる長さ 1 以上 10 以下の文字列
- N,K は整数である
入力
入力は以下の形式で標準入力から与えられる。
N K S_1 \vdots S_N
出力
答えを出力せよ。
入力例 1
3 2 123 45 6
出力例 1
45123
123, 45, 6 から 2 個選んで連結してできる文字列は 12345, 1236, 45123, 456, 6123, 645 の 6 種類あります。
これを十進表記の整数と解釈したときの最大値は 45123 です。
入力例 2
5 3 00000 00 1 0000 000
出力例 2
1000000000
入力例 3
9 9 0000000001 000000002 00000003 0000004 000005 00006 0007 008 09
出力例 3
90080007000060000050000004000000030000000020000000001
答えは先頭の余分なゼロなしで出力する必要があります。
Score : 550 points
Problem Statement
You are given N strings S_1,\ldots,S_N consisting of digits.
Find the maximum possible value, when interpreted as a decimal integer (after removing extra leading zeros), of a string obtained by choosing exactly K of these strings and concatenating them in any order of your choice.
Here, the value obtained by interpreting a string consisting entirely of the character 0 as a decimal integer after removing extra leading zeros is defined to be 0.
Constraints
- 1 \leq K \leq N \leq 10^5
- S_i is a string of length between 1 and 10 (inclusive) consisting of digits.
- N and K are integers.
Input
The input is given from Standard Input in the following format:
N K S_1 \vdots S_N
Output
Output the answer.
Sample Input 1
3 2 123 45 6
Sample Output 1
45123
There are six strings obtained by choosing two of 123, 45, 6 and concatenating them: 12345, 1236, 45123, 456, 6123, 645.
Among these, the maximum value when interpreted as a decimal integer is 45123.
Sample Input 2
5 3 00000 00 1 0000 000
Sample Output 2
1000000000
Sample Input 3
9 9 0000000001 000000002 00000003 0000004 000005 00006 0007 008 09
Sample Output 3
90080007000060000050000004000000030000000020000000001
The answer must be output without extra leading zeros.
Time Limit: 5 sec / Memory Limit: 1024 MiB
配点 : 600 点
問題文
0 から K-1 までの番号で表される K 種類の記号があります。
各記号は、母音であるか母音でないかのいずれかです。 V_j = 1 のとき記号 j は母音であり、V_j = 0 のとき記号 j は母音ではありません。
ある記号列の音節数を、その記号列における母音のみからなる連続部分列として極大なものの個数とします。形式的には、長さ N の記号列 (a_1, \dots, a_N) の音節数を、1 \leq l \leq r \leq N を満たす整数の組 (l,r) であって以下をすべて満たすものの個数とします。
- 記号 a_l, \dots, a_r はすべて母音である。
- l > 1 ならば、記号 a_{l-1} は母音でない。
- r < N ならば、記号 a_{r+1} は母音でない。
長さ N の数列 A = (A_1, \dots, A_N) が与えられます。k = 0, \dots, K-1 について、以下の問題に答えてください。
- 長さ N の記号列 A' = (A'_1, \dots, A'_N) を、A'_i := (A_i + k) \bmod K として定める。このとき、A' の音節数はいくつか?
入力の形式
今回の問題の入力は特殊な形式で行われます。
標準入力からは A_1, \dots, A_N の代わりに整数 \mathrm{seed}, M, b_1, \dots, b_M が与えられます。 このとき、以下の疑似コードで表される計算によって A_1, \dots, A_N を復元してください。
なお、疑似コード中の変数はすべて符号なし 64bit 整数であるものとします。 また、s \oplus t は s,t の bitwise XOR (排他的論理和) を、s \gg t は \lfloor s / 2^t \rfloor (右シフト演算) を、s \ll t は s \times 2^t (左シフト演算) を表すものとします。
\mathrm{state} \leftarrow \mathrm{seed}
for i = 1, \dots, N:
if i \leq M:
A_i \leftarrow b_i
else:
x \leftarrow \left( ((\mathrm{state} \gg 18) \oplus \mathrm{state}) \gg 27 \right) \bmod 2^{32}
r \leftarrow \mathrm{state} \gg 59
y \leftarrow \left( (x \gg r) + (x \ll (32-r)) \right) \bmod 2^{32}
A_i \leftarrow y \bmod K
\mathrm{state} \leftarrow (\mathrm{state} \times 6364136223846793005 + 2026081520260815) \bmod 2^{64}
制約
- 1 \leq N \leq 7 \times 10^6
- 1 \leq K \leq 2300
- 0 \leq A_i \leq K-1 (1 \leq i \leq N)
- V_j \in \{0,1\} (0 \leq j \leq K-1)
- 0 \leq \mathrm{seed} \leq 2^{60} - 1
- 1 \leq M \leq \min(N, 10^5)
- 0 \leq b_i \leq K-1 (1 \leq i \leq M)
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K \mathrm{seed} M
b_1 b_2 \cdots b_M
V_0 V_1 \cdots V_{K-1}
出力
K 行出力せよ。m 行目 (1 \leq m \leq K) には、k = m-1 のときの答えを出力せよ。
入力例 1
4 6 12233445577788999 4 4 2 4 1 1 1 0 0 1 0
出力例 1
2 0 1 2 1 2
この入力例において A = (4,2,4,1) です。
- k = 0 のとき A' = (4,2,4,1) であり、このときの音節数は 2 です。
- k = 1 のとき A' = (5,3,5,2) であり、このときの音節数は 0 です。
- k = 2 のとき A' = (0,4,0,3) であり、このときの音節数は 1 です。
- k = 3 のとき A' = (1,5,1,4) であり、このときの音節数は 2 です。
- k = 4 のとき A' = (2,0,2,5) であり、このときの音節数は 1 です。
- k = 5 のとき A' = (3,1,3,0) であり、このときの音節数は 2 です。
入力例 2
15 12 998154573227378904 2 5 6 0 0 1 1 0 1 0 0 1 1 0 1
出力例 2
4 4 3 3 3 4 4 4 3 3 3 4
この入力例において A = (5, 6, 0, 6, 8, 8, 8, 3, 0, 2, 3, 7, 3, 2, 5) です。
入力例 3
7000000 15 409873722375451899 3 7 0 4 1 0 1 1 1 0 1 1 1 0 1 0 1 0 0
出力例 3
1680078 1681239 1679837 1680730 1680470 1679454 1679615 1679371 1681263 1679670 1680218 1680010 1680211 1680521 1681744
Score : 600 points
Problem Statement
There are K kinds of symbols numbered 0 to K-1.
Each symbol is either a vowel or not a vowel. If V_j = 1, symbol j is a vowel; if V_j = 0, symbol j is not a vowel.
Define the number of syllables of a symbol string as the number of maximal contiguous substrings of that string consisting of vowels. Formally, the number of syllables of a length-N symbol string (a_1, \dots, a_N) is defined as the number of pairs of integers (l,r) satisfying 1 \leq l \leq r \leq N and all of the following:
- The symbols a_l, \dots, a_r are all vowels.
- If l > 1, symbol a_{l-1} is not a vowel.
- If r < N, symbol a_{r+1} is not a vowel.
You are given a length-N sequence A = (A_1, \dots, A_N). For each k = 0, \dots, K-1, answer the following question:
- Define a length-N symbol string A' = (A'_1, \dots, A'_N) by A'_i := (A_i + k) \bmod K. What is the number of syllables of A'?
Input Format
The input for this problem is given in a special format.
Instead of A_1, \dots, A_N, the integers \mathrm{seed}, M, b_1, \dots, b_M are given from Standard Input. Restore A_1, \dots, A_N using the computation represented by the following pseudocode.
Here, all variables in the pseudocode are unsigned 64-bit integers. s \oplus t denotes the bitwise XOR of s and t, s \gg t denotes \lfloor s / 2^t \rfloor (the right shift operation), and s \ll t denotes s \times 2^t (the left shift operation).
\mathrm{state} \leftarrow \mathrm{seed}
for i = 1, \dots, N:
if i \leq M:
A_i \leftarrow b_i
else:
x \leftarrow \left( ((\mathrm{state} \gg 18) \oplus \mathrm{state}) \gg 27 \right) \bmod 2^{32}
r \leftarrow \mathrm{state} \gg 59
y \leftarrow \left( (x \gg r) + (x \ll (32-r)) \right) \bmod 2^{32}
A_i \leftarrow y \bmod K
\mathrm{state} \leftarrow (\mathrm{state} \times 6364136223846793005 + 2026081520260815) \bmod 2^{64}
Constraints
- 1 \leq N \leq 7 \times 10^6
- 1 \leq K \leq 2300
- 0 \leq A_i \leq K-1 (1 \leq i \leq N)
- V_j \in \{0,1\} (0 \leq j \leq K-1)
- 0 \leq \mathrm{seed} \leq 2^{60} - 1
- 1 \leq M \leq \min(N, 10^5)
- 0 \leq b_i \leq K-1 (1 \leq i \leq M)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K \mathrm{seed} M
b_1 b_2 \cdots b_M
V_0 V_1 \cdots V_{K-1}
Output
Output K lines. The m-th line (1 \leq m \leq K) should contain the answer for k = m-1.
Sample Input 1
4 6 12233445577788999 4 4 2 4 1 1 1 0 0 1 0
Sample Output 1
2 0 1 2 1 2
In this input, A = (4,2,4,1).
- For k = 0, A' = (4,2,4,1), and the number of syllables is 2.
- For k = 1, A' = (5,3,5,2), and the number of syllables is 0.
- For k = 2, A' = (0,4,0,3), and the number of syllables is 1.
- For k = 3, A' = (1,5,1,4), and the number of syllables is 2.
- For k = 4, A' = (2,0,2,5), and the number of syllables is 1.
- For k = 5, A' = (3,1,3,0), and the number of syllables is 2.
Sample Input 2
15 12 998154573227378904 2 5 6 0 0 1 1 0 1 0 0 1 1 0 1
Sample Output 2
4 4 3 3 3 4 4 4 3 3 3 4
In this input, A = (5, 6, 0, 6, 8, 8, 8, 3, 0, 2, 3, 7, 3, 2, 5).
Sample Input 3
7000000 15 409873722375451899 3 7 0 4 1 0 1 1 1 0 1 1 1 0 1 0 1 0 0
Sample Output 3
1680078 1681239 1679837 1680730 1680470 1679454 1679615 1679371 1681263 1679670 1680218 1680010 1680211 1680521 1681744