実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
0 と 1 の 2 種類の文字からなる文字列 s が与えられます。
s に含まれる 0 を 1 に、1 を 0 に置き換えた文字列を出力してください。
制約
- s の長さは 1 以上 10 以下
- s は
0と1の 2 種類の文字からなる
入力
入力は以下の形式で標準入力から与えられる。
s
出力
答えを 1 行で出力せよ。
入力例 1
01
出力例 1
10
s の 1 文字目は 1 なので、1 文字目に出力すべき文字は 0 です。
s の 2 文字目は 0 なので、2 文字目に出力すべき文字は 1 です。
入力例 2
1011
出力例 2
0100
入力例 3
100100001
出力例 3
011011110
Score : 100 points
Problem Statement
You are given a string s consisting of two kinds of characters, 0 and 1.
Print the string obtained by replacing 0 with 1 and 1 with 0 in s.
Constraints
- The length of s is between 1 and 10, inclusive.
- s consists of two kinds of characters,
0and1.
Input
The input is given from Standard Input in the following format:
s
Output
Print the answer in a single line.
Sample Input 1
01
Sample Output 1
10
The 1-st character of s is 1, so the 1-st character to print is 0.
The 2-nd character of s is 0, so the 2-nd character to print is 1.
Sample Input 2
1011
Sample Output 2
0100
Sample Input 3
100100001
Sample Output 3
011011110
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
文字列 S が与えられるので、この文字列が Hello,World! と完全に一致するなら AC 、そうでないなら WA と出力してください。
「完全に一致する」とは?
文字列 A と B が完全に一致するとは、文字列 A と B の長さが等しく、かつ全ての 1 \le i \le |A| を満たす整数 i について A の先頭から i 文字目と B の先頭から i 文字目とが(英大文字か小文字かも含めて)一致することを指します。制約
- 1 \le |S| \le 15
- S は英大小文字,
,,!のみからなる
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
Hello,World!
出力例 1
AC
文字列 S は Hello,World! と完全に一致します。
入力例 2
Hello,world!
出力例 2
WA
先頭から 7 文字目の W が、 Hello,World! では大文字ですが S では小文字です。よって S は Hello,World! と一致しません。
入力例 3
Hello!World!
出力例 3
WA
Score : 100 points
Problem Statement
Given a string S, print AC if it perfectly matches Hello,World!; otherwise, print WA.
What is a perfect match?
Strings A is said to perfectly match B when the length of A is equal to that of B, and the i-th character of A is the same as the i-th character of B for every integer i such that 1 \le i \le |A|.Constraints
- 1 \le |S| \le 15
- S consists of English lowercase letters, English uppercase letters,
,, and!.
Input
Input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
Hello,World!
Sample Output 1
AC
The string S perfectly matches Hello,World!.
Sample Input 2
Hello,world!
Sample Output 2
WA
The seventh character from the beginning should be an uppercase W in Hello,World!, but S has a lowercase w in that position. Thus, S does not match Hello,World!.
Sample Input 3
Hello!World!
Sample Output 3
WA
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
0 と 1 からなる長さ 64 の数列 A=(A_0,A_1,\dots,A_{63}) が与えられます。
A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} を求めてください。
制約
- A_i は 0 または 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
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
横書きの文章が与えられます。縦書きに直してください。空白を
*で埋めてください。
N 個の、英小文字からなる文字列 S_1,S_2,\dots,S_N が与えられます。これらの文字列の長さの最大値を M とします。
以下の条件を満たす M 個の文字列 T_1,T_2,\dots,T_M を出力してください。
- 各 T_i は英小文字および
*からなる - 各 T_i の末尾は
*でない - 各 1 \leq i \leq N について、次が成り立つ
- 各 1 \leq j \leq |S_i| について、T_j の N-i+1 文字目が存在し、T_1,T_2,\dots,T_{|S_i|} それぞれの N-i+1 文字目をこの順に連結したものは S_i と一致する
- 各 |S_i| + 1 \leq j \leq M について、T_j の N-i+1 文字目は存在しないか、
*である
ただし、|S_i| で文字列 S_i の長さを表します。
制約
- N は 1 以上 100 以下の整数
- S_i は長さ 1 以上 100 以下の英小文字からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
答えを以下の形式で出力せよ。
T_1 T_2 \vdots T_M
入力例 1
3 abc de fghi
出力例 1
fda geb h*c i
T_3 の 2 文字目を * とすることで、 c が正しい位置に来ます。
T_4 の 2,3 文字目を * とした場合、T_4 の末尾が * となり、条件を満たしません。
入力例 2
3 atcoder beginner contest
出力例 2
cba oet ngc tio end sne ter *r
Score : 200 points
Problem Statement
You are given a horizontally written text. Convert it to vertical writing, filling spaces with
*.
You are given N strings S_1, S_2, \dots, S_N consisting of lowercase English letters. Let M be the maximum length of these strings.
Print M strings T_1, T_2, \dots, T_M that satisfy the following conditions:
- Each T_i consists of lowercase English letters and
*. - Each T_i does not end with
*. - For each 1 \leq i \leq N, the following holds:
- For each 1 \leq j \leq |S_i|, the (N-i+1)-th character of T_j exists, and the concatenation of the (N-i+1)-th characters of T_1, T_2, \dots, T_{|S_i|} in this order equals S_i.
- For each |S_i| + 1 \leq j \leq M, the (N-i+1)-th character of T_j either does not exist or is
*.
Here, |S_i| denotes the length of the string S_i.
Constraints
- N is an integer between 1 and 100, inclusive.
- Each S_i is a string of lowercase English letters with length between 1 and 100, inclusive.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the answer in the following format:
T_1 T_2 \vdots T_M
Sample Input 1
3 abc de fghi
Sample Output 1
fda geb h*c i
Placing * as the 2nd character of T_3 puts the c in the correct position.
On the other hand, placing * as the 2nd and 3rd characters of T_4 would make T_4 end with *, which violates the condition.
Sample Input 2
3 atcoder beginner contest
Sample Output 2
cba oet ngc tio end sne ter *r
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
ポエムオンラインジャッジ (Poem Online Judge, 以下 POJ と表記) は提出された文字列に得点をつけるオンラインジャッジです。
POJ に N 回の提出がありました。早い方から i 番目の提出では文字列 S_i が提出されて、得点は T_i でした。(同じ文字列が複数回提出される場合もあります)
ただし、POJ では 同じ文字列を提出しても得点が等しいとは限らない のに注意してください。
N 回の提出のうち、その提出よりも早い提出であって文字列が一致するものが存在しないような提出を オリジナル であると呼びます。
また、オリジナルな提出の中で最も得点が高いものを 最優秀賞 と呼びます。ただし、そのような提出が複数ある場合は、最も提出が早いものを最優秀賞とします。
最優秀賞は早い方から何番目の提出ですか?
制約
- 1 \leq N \leq 10^5
- S_i は英小文字からなる文字列
- S_i の長さは 1 以上 10 以下
- 0 \leq T_i \leq 10^9
- N, T_i は整数
入力
入力は以下の形式で標準入力から与えられる。
N S_1 T_1 S_2 T_2 \vdots S_N T_N
出力
答えを出力せよ。
入力例 1
3 aaa 10 bbb 20 aaa 30
出力例 1
2
以下では早い方から i 番目の提出を提出 i と呼びます。
オリジナルな提出は提出 1 と 提出 2 です。提出 3 は提出 1 と文字列が一致しているためオリジナルではありません。
オリジナルな提出のうち最も得点が高い提出は提出 2 です。よってこれが最優秀賞になります。
入力例 2
5 aaa 9 bbb 10 ccc 10 ddd 10 bbb 11
出力例 2
2
オリジナルな提出は提出 1・提出 2・提出 3・提出 4 です。
その中で最も得点が高い提出は提出 2・提出 3・提出 4 です。この場合はこの中でもっとも提出の早い提出 2 を最優秀賞とします。
このように、オリジナルな提出の中で最も得点が高い提出が複数ある場合は、さらにその中で最も提出が早いものを最優秀賞とするのに注意してください。
入力例 3
10 bb 3 ba 1 aa 4 bb 1 ba 5 aa 9 aa 2 ab 6 bb 5 ab 3
出力例 3
8
Score : 300 points
Problem Statement
Poem Online Judge (POJ) is an online judge that gives scores to submitted strings.
There were N submissions to POJ. In the i-th earliest submission, string S_i was submitted, and a score of T_i was given. (The same string may have been submitted multiple times.)
Note that POJ may not necessarily give the same score to submissions with the same string.
A submission is said to be an original submission if the string in the submission is never submitted in any earlier submission.
A submission is said to be the best submission if it is an original submission with the highest score. If there are multiple such submissions, only the earliest one is considered the best submission.
Find the index of the best submission.
Constraints
- 1 \leq N \leq 10^5
- S_i is a string consisting of lowercase English characters.
- S_i has a length between 1 and 10, inclusive.
- 0 \leq T_i \leq 10^9
- N and T_i are integers.
Input
Input is given from Standard Input in the following format:
N S_1 T_1 S_2 T_2 \vdots S_N T_N
Output
Print the answer.
Sample Input 1
3 aaa 10 bbb 20 aaa 30
Sample Output 1
2
We will refer to the i-th earliest submission as Submission i.
Original submissions are Submissions 1 and 2. Submission 3 is not original because it has the same string as that in Submission 1.
Among the original submissions, Submission 2 has the highest score. Therefore, this is the best submission.
Sample Input 2
5 aaa 9 bbb 10 ccc 10 ddd 10 bbb 11
Sample Output 2
2
Original submissions are Submissions 1, 2, 3, and 4.
Among them, Submissions 2, 3, and 4 have the highest scores. In this case, the earliest submission among them, Submission 2, is the best.
As in this sample, beware that if multiple original submissions have the highest scores, only the one with the earliest among them is considered the best submission.
Sample Input 3
10 bb 3 ba 1 aa 4 bb 1 ba 5 aa 9 aa 2 ab 6 bb 5 ab 3
Sample Output 3
8
実行時間制限: 3 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
長さ N の数列 A = (a_1, a_2, \dots, a_N) があります。
以下で説明される Q 個のクエリに答えてください。
- クエリ i : 整数の組 (x_i, k_i) が与えられます。A の要素を a_1, a_2, \dots と前から順に見ていったときに、数 x_i が k_i 回目に登場するのは A の前から何番目の要素を見たときかを出力してください。
ただし条件を満たす要素が存在しない場合は -1 を出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 0 \leq a_i \leq 10^9 (1 \leq i \leq N)
- 0 \leq x_i \leq 10^9 (1 \leq i \leq Q)
- 1 \leq k_i \leq N (1 \leq i \leq Q)
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N Q a_1 a_2 \dots a_N x_1 k_1 x_2 k_2 \vdots x_Q k_Q
出力
Q 行出力せよ。i 行目ではクエリ i に対する答えを出力せよ。
入力例 1
6 8 1 1 2 3 1 2 1 1 1 2 1 3 1 4 2 1 2 2 2 3 4 1
出力例 1
1 2 5 -1 3 6 -1 -1
A の中で 1 は a_1, a_2, a_5 に登場します。よって、クエリ 1 からクエリ 4 の答えは順に 1, 2, 5, -1 となります。
入力例 2
3 2 0 1000000000 999999999 1000000000 1 123456789 1
出力例 2
2 -1
Score : 300 points
Problem Statement
We have a sequence of N numbers: A = (a_1, a_2, \dots, a_N).
Process the Q queries explained below.
- Query i: You are given a pair of integers (x_i, k_i). Let us look at the elements of A one by one from the beginning: a_1, a_2, \dots Which element will be the k_i-th occurrence of the number x_i?
Print the index of that element, or -1 if there is no such element.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 0 \leq a_i \leq 10^9 (1 \leq i \leq N)
- 0 \leq x_i \leq 10^9 (1 \leq i \leq Q)
- 1 \leq k_i \leq N (1 \leq i \leq Q)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q a_1 a_2 \dots a_N x_1 k_1 x_2 k_2 \vdots x_Q k_Q
Output
Print Q lines. The i-th line should contain the answer to Query i.
Sample Input 1
6 8 1 1 2 3 1 2 1 1 1 2 1 3 1 4 2 1 2 2 2 3 4 1
Sample Output 1
1 2 5 -1 3 6 -1 -1
1 occurs in A at a_1, a_2, a_5. Thus, the answers to Query 1 through 4 are 1, 2, 5, -1 in this order.
Sample Input 2
3 2 0 1000000000 999999999 1000000000 1 123456789 1
Sample Output 2
2 -1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
縦 N 行 横 N 列のマスからなるグリッドがあります。ここで、N は 45 以下の奇数です。
上から i 行目、左から j 列目のマスをマス (i,j) と表します。
このグリッドに、以下の条件を満たすように高橋君と 1 から N^2-1 までの番号がついた N^2-1 個のパーツからなる 1 匹の龍を配置します。
- 高橋君はグリッドの中央、すなわちマス (\frac{N+1}{2},\frac{N+1}{2}) に配置しなければならない。
- 高橋君がいるマスを除く各マスには龍のパーツをちょうど 1 つ配置しなければならない。
- 2 \leq x \leq N^2-1 を満たす全ての整数 x について、龍のパーツ x はパーツ x-1 があるマスと辺で隣接するマスに配置しなければならない。
- マス (i,j) とマス (k,l) が辺で隣接するとは、|i-k|+|j-l|=1 であることを意味します。
条件を満たす配置方法を 1 つ出力してください。なお、条件を満たす配置は必ず存在します。
制約
- 3 \leq N \leq 45
- N は奇数である
入力
入力は以下の形式で標準入力から与えられる。
N
出力
N 行出力せよ。
X_{i,j} を、マス (i,j) に高橋君を配置するとき T、パーツ x を配置するとき x とし、i 行目には X_{i,1},\ldots,X_{i,N} を空白区切りで出力せよ。
入力例 1
5
出力例 1
1 2 3 4 5 16 17 18 19 6 15 24 T 20 7 14 23 22 21 8 13 12 11 10 9
この他、以下の出力も条件をすべて満たすため正解となります。
9 10 11 14 15 8 7 12 13 16 5 6 T 18 17 4 3 24 19 20 1 2 23 22 21
一方、以下の出力はそれぞれ不正解となります。
高橋君が中央にいない。
1 2 3 4 5 10 9 8 7 6 11 12 13 14 15 20 19 18 17 16 21 22 23 24 T
パーツ 23 とパーツ 24 のあるマスが辺で隣接していない。
1 2 3 4 5 10 9 8 7 6 11 12 24 22 23 14 13 T 21 20 15 16 17 18 19
Score : 350 points
Problem Statement
There is a grid with N rows and N columns, where N is an odd number at most 45.
Let (i,j) denote the cell at the i-th row from the top and j-th column from the left.
In this grid, you will place Takahashi and a dragon consisting of N^2-1 parts numbered 1 to N^2-1 in such a way that satisfies the following conditions:
- Takahashi must be placed at the center of the grid, that is, in cell (\frac{N+1}{2},\frac{N+1}{2}).
- Except for the cell where Takahashi is, exactly one dragon part must be placed in each cell.
- For every integer x satisfying 2 \leq x \leq N^2-1, the dragon part x must be placed in a cell adjacent by an edge to the cell containing part x-1.
- Cells (i,j) and (k,l) are said to be adjacent by an edge if and only if |i-k|+|j-l|=1.
Print one way to arrange the parts to satisfy the conditions. It is guaranteed that there is at least one arrangement that satisfies the conditions.
Constraints
- 3 \leq N \leq 45
- N is odd.
Input
The input is given from Standard Input in the following format:
N
Output
Print N lines.
The i-th line should contain X_{i,1},\ldots,X_{i,N} separated by spaces, where X_{i,j} is T when placing Takahashi in cell (i,j) and x when placing part x there.
Sample Input 1
5
Sample Output 1
1 2 3 4 5 16 17 18 19 6 15 24 T 20 7 14 23 22 21 8 13 12 11 10 9
The following output also satisfies all the conditions and is correct.
9 10 11 14 15 8 7 12 13 16 5 6 T 18 17 4 3 24 19 20 1 2 23 22 21
On the other hand, the following outputs are incorrect for the reasons given.
Takahashi is not at the center.
1 2 3 4 5 10 9 8 7 6 11 12 13 14 15 20 19 18 17 16 21 22 23 24 T
The cells containing parts 23 and 24 are not adjacent by an edge.
1 2 3 4 5 10 9 8 7 6 11 12 24 22 23 14 13 T 21 20 15 16 17 18 19
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 450 点
問題文
整数 N,M が与えられるので、 \lfloor N/M \rfloor を \color{red}{10007} で割った余りを求めてください。
ここで、 \lfloor x \rfloor は x 以下で最大の整数を表します。 例えば、 \lfloor 3.14 \rfloor=3, \lfloor 10 \rfloor = 10 です。
但し、この問題では N は直接与えられず、ランレングス圧縮された形で与えられます。
具体的には、 N は K 個の「数字 c_i と整数 l_i の組」からなる列で表現されます。
元の N を復元するには、以下の手順を用います。
- 最初、文字列 S を空文字列とする。
- i=1,2,\dots,K について、以下を繰り返す。
- S の末尾に数字 c_i を l_i 個付け加える。
- 最終的な S をひとつの整数として解釈したとき、その整数が N である。
制約
- 1 \le M \le 10^4
- 1 \le K \le 10^5
- c_i は 0,1,2,3,4,5,6,7,8,9 いずれかの数字
- 1 \le l_i \le 10^9
- c_1 \neq 0
- M,K,l_i は整数
入力
入力は以下の形式で標準入力から与えられる。
K M c_1 l_1 c_2 l_2 \vdots c_K l_K
出力
答えを出力せよ。
入力例 1
6 7 3 1 1 1 6 1 2 2 7 2 6 2
出力例 1
3797
この入力では N=316227766,M=7 です。
\lfloor 316227766/7 \rfloor = 45175395 であり、これを 10007 で割った余りである 3797 が最終的な答えとなります。
入力例 2
1 1 1 1
出力例 2
1
入力例 3
10 9999 9 419921892 9 923650333 6 476449815 1 8837775 2 141135534 5 462618481 3 202652735 0 771538044 4 321458589 0 570032864
出力例 3
8437
Score : 450 points
Problem Statement
You are given integers N and M. Find the remainder when \lfloor N/M \rfloor is divided by \color{red}{10007}.
Here, \lfloor x \rfloor denotes the largest integer not exceeding x. For example, \lfloor 3.14 \rfloor=3 and \lfloor 10 \rfloor = 10.
In this problem, N is not given directly; instead, it is given in run-length encoded form.
Specifically, N is represented by a sequence of K pairs of a digit c_i and an integer l_i.
To recover the original N, use the following procedure.
- Initially, let string S be the empty string.
- For i=1,2,\dots,K, repeat the following.
- Append l_i copies of digit c_i to the end of S.
- Interpret the final S as a single integer; that integer is N.
Constraints
- 1 \le M \le 10^4
- 1 \le K \le 10^5
- c_i is one of the digits 0,1,2,3,4,5,6,7,8,9.
- 1 \le l_i \le 10^9
- c_1 \neq 0
- M,K,l_i are integers.
Input
The input is given from Standard Input in the following format:
K M c_1 l_1 c_2 l_2 \vdots c_K l_K
Output
Output the answer.
Sample Input 1
6 7 3 1 1 1 6 1 2 2 7 2 6 2
Sample Output 1
3797
In this input, N=316227766 and M=7.
\lfloor 316227766/7 \rfloor = 45175395, and the remainder when this is divided by 10007 is 3797, which is the final answer.
Sample Input 2
1 1 1 1
Sample Output 2
1
Sample Input 3
10 9999 9 419921892 9 923650333 6 476449815 1 8837775 2 141135534 5 462618481 3 202652735 0 771538044 4 321458589 0 570032864
Sample Output 3
8437
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 550 点
問題文
正整数 N, M, K と、長さ N の正整数列 (C_1, C_2, \ldots, C_N) が与えられるので、 r = 0, 1, 2, \ldots, N-1 の場合それぞれについて、下記の問題の答えを出力してください。
色がついた N 個のボールからなる列があり、i = 1, 2, \ldots, N について、列の先頭から i 番目にあるボールの色は C_i です。 また、1 から M の番号がつけられた M 個の空の箱があります。
下記の手順を行った後に箱に入っているボールの総数を求めてください。
まず、下記の操作を r 回行う。
- 列の先頭のボール 1 個を列の最後尾に移動する。
その後、列にボールが 1 個以上残っている限り、下記の操作を繰り返す。
- 列の先頭のボールと同じ色のボールが既に 1 個以上 K 個未満入っている箱が存在する場合、その箱に列の先頭のボールを入れる。
- そのような箱が存在しない場合、
- 空の箱が存在するなら、そのうち番号が最小のものに、列の先頭のボールを入れる。
- 空の箱が存在しない場合、列の先頭のボールをどの箱にも入れず、食べる。
制約
- 入力される値はすべて整数
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M, K \leq N
- 1 \leq C_i \leq N
入力
入力は以下の形式で標準入力から与えられる。
N M K C_1 C_2 \ldots C_N
出力
r = 0, 1, 2, \ldots, N-1 のそれぞれの場合の問題の答え X_r を下記の通りに N 行にわたって出力せよ。
X_0
X_1
\vdots
X_{N-1}
入力例 1
7 2 2 1 2 3 5 2 5 4
出力例 1
3 3 3 4 4 3 2
例として、r = 1 の場合の手順を説明します。 まず「列の先頭のボール 1 個を列の最後尾に移動する」ことを 1 回行い、ボールの色の列は (2, 3, 5, 2, 5, 4, 1) となります。 その後、ボールを箱に入れていく操作を下記の通りに行います。
- 1 回目の操作:先頭のボールの色は 2 です。色 2 のボールが 1 個以上 2 個未満入った箱は存在しないため、先頭のボールを空の箱のうち番号が最小の箱 1 に入れます。
- 2 回目の操作:先頭のボールの色は 3 です。色 3 のボールが 1 個以上 2 個未満入った箱は存在しないため、先頭のボールを空の箱のうち番号が最小の箱 2 に入れます。
- 3 回目の操作:先頭のボールの色は 5 です。色 5 のボールが 1 個以上 2 個未満入った箱も空の箱も存在しないため、先頭のボールを食べます。
- 4 回目の操作:先頭のボールの色は 2 です。色 2 のボールが 1 個以上 2 個未満入った箱として箱 1 が存在するため、先頭のボールを箱 1 に入れます。
- 5 回目の操作:先頭のボールの色は 5 です。色 5 のボールが 1 個以上 2 個未満入った箱も空の箱も存在しないため、先頭のボールを食べます。
- 6 回目の操作:先頭のボールの色は 4 です。色 4 のボールが 1 個以上 2 個未満入った箱も空の箱も存在しないため、先頭のボールを食べます。
- 7 回目の操作:先頭のボールの色は 1 です。色 1 のボールが 1 個以上 2 個未満入った箱も空の箱も存在しないため、先頭のボールを食べます。
最終的に箱に入っているボールの総数は 3 個であるので、r = 1 の問題の答えは 3 です。
入力例 2
20 5 4 20 2 20 2 7 3 11 20 3 8 7 9 1 11 8 20 2 18 11 18
出力例 2
14 14 14 14 13 13 13 11 8 9 9 11 13 14 14 14 14 14 14 13
Score: 550 points
Problem Statement
You are given positive integers N, M, K, and a sequence of positive integers of length N, (C_1, C_2, \ldots, C_N). For each r = 0, 1, 2, \ldots, N-1, print the answer to the following problem.
There is a sequence of N colored balls. For i = 1, 2, \ldots, N, the color of the i-th ball from the beginning of the sequence is C_i. Additionally, there are M empty boxes numbered 1 to M.
Determine the total number of balls in the boxes after performing the following steps.
First, perform the following operation r times.
- Move the frontmost ball in the sequence to the end of the sequence.
Then, repeat the following operation as long as at least one ball remains in the sequence.
- If there is a box that already contains at least one but fewer than K balls of the same color as the frontmost ball in the sequence, put the frontmost ball into that box.
- If there is no such box,
- If there is an empty box, put the frontmost ball into the one with the smallest box number.
- If there are no empty boxes, eat the frontmost ball without putting it into any box.
Constraints
- All input values are integers.
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M, K \leq N
- 1 \leq C_i \leq N
Input
The input is given from Standard Input in the following format:
N M K C_1 C_2 \ldots C_N
Output
Print the answer X_r to the problem for each r = 0, 1, 2, \ldots, N-1 over N lines as follows:
X_0
X_1
\vdots
X_{N-1}
Sample Input 1
7 2 2 1 2 3 5 2 5 4
Sample Output 1
3 3 3 4 4 3 2
For example, let us explain the procedure for r = 1. First, perform the operation "Move the frontmost ball in the sequence to the end of the sequence" once, and the sequence of ball colors becomes (2, 3, 5, 2, 5, 4, 1). Then, proceed with the operation of putting balls into boxes as follows:
- First operation: The color of the frontmost ball is 2. There is no box with at least one but fewer than two balls of color 2, so put the frontmost ball into the empty box with the smallest box number, box 1.
- Second operation: The color of the frontmost ball is 3. There is no box with at least one but fewer than two balls of color 3, so put the frontmost ball into the empty box with the smallest box number, box 2.
- Third operation: The color of the frontmost ball is 5. There is no box with at least one but fewer than two balls of color 5 and no empty boxes, so eat the frontmost ball.
- Fourth operation: The color of the frontmost ball is 2. There is a box, box 1, with at least one but fewer than two balls of color 2, so put the frontmost ball into box 1.
- Fifth operation: The color of the frontmost ball is 5. There is no box with at least one but fewer than two balls of color 5 and no empty boxes, so eat the frontmost ball.
- Sixth operation: The color of the frontmost ball is 4. There is no box with at least one but fewer than two balls of color 4 and no empty boxes, so eat the frontmost ball.
- Seventh operation: The color of the frontmost ball is 1. There is no box with at least one but fewer than two balls of color 1 and no empty boxes, so eat the frontmost ball.
The final total number of balls in the boxes is 3, so the answer to the problem for r = 1 is 3.
Sample Input 2
20 5 4 20 2 20 2 7 3 11 20 3 8 7 9 1 11 8 20 2 18 11 18
Sample Output 2
14 14 14 14 13 13 13 11 8 9 9 11 13 14 14 14 14 14 14 13