Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英大文字からなる長さ 3 の文字列 S が与えられます。S が ACE、BDF、CEG、DFA、EGB、FAC、GBD のいずれかと等しいとき Yes を、そうでないとき No を出力してください。
制約
- S は英大文字からなる長さ 3 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S が ACE、BDF、CEG、DFA、EGB、FAC、GBD のいずれかと等しいとき Yes を、そうでないとき No を出力せよ。
入力例 1
ABC
出力例 1
No
S = ABC のとき、S は ACE、BDF、CEG、DFA、EGB、FAC、GBD のいずれとも等しくないので No を出力します。
入力例 2
FAC
出力例 2
Yes
入力例 3
XYX
出力例 3
No
Score : 100 points
Problem Statement
Given a length-3 string S consisting of uppercase English letters, print Yes if S equals one of ACE, BDF, CEG, DFA, EGB, FAC, and GBD; print No otherwise.
Constraints
- S is a length-3 string consisting of uppercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Print Yes if S equals one of ACE, BDF, CEG, DFA, EGB, FAC, and GBD; print No otherwise.
Sample Input 1
ABC
Sample Output 1
No
When S = ABC, S does not equal any of ACE, BDF, CEG, DFA, EGB, FAC, and GBD, so No should be printed.
Sample Input 2
FAC
Sample Output 2
Yes
Sample Input 3
XYX
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は 2 次元コード TaK Code を考案しました。以下の条件を全て満たすものが TaK Code です。
- 縦 9 マス 横 9 マスの領域である
- 左上及び右下の縦 3 マス 横 3 マスの領域に含まれる計 18 マスは全て黒である
- 左上及び右下の縦 3 マス 横 3 マスの領域に八方位で隣接する計 14 マスは全て白である
TaK Code を回転させることはできません。
縦 N マス、横 M マスのグリッドがあります。
グリッドの状態は N 個の長さ M の文字列 S_1,\ldots,S_N で与えられ、上から i 行目左から j 列目のマスは S_i の j 文字目が # のとき黒、. のとき白です。
グリッドに完全に含まれる縦 9 マス横 9 マスの領域で、TaK Code の条件を満たす箇所を全て求めてください。
制約
- 9 \leq N,M \leq 100
- N,M は整数である
- S_i は
.および#のみからなる長さ M の文字列である
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 \vdots S_N
出力
上から i 行目左から j 列目のマスを左上とする縦 9 マス 横 9 マスの領域が TaK Code の条件を満たす (i,j) の組全てを辞書順の昇順で 1 行に 1 組ずつ、i,j をこの順に空白区切りで出力せよ。
(i,j) の組の辞書順の昇順とは、i の昇順、i が等しい組は j の昇順にすることである。
入力例 1
19 18 ###......###...... ###......###...... ###..#...###..#... ..............#... .................. .................. ......###......### ......###......### ......###......### .###.............. .###......##...... .###.............. ............###... ...##.......###... ...##.......###... .......###........ .......###........ .......###........ ........#.........
出力例 1
1 1 1 10 7 7 10 2
TaK Code は以下のものです。# が黒マス、. が白マス、? が白黒どちらでもよいマスを表します。
###.????? ###.????? ###.????? ....????? ????????? ?????.... ?????.### ?????.### ?????.###
入力で与えられたグリッドの上から 10 マス目左から 2 列目のマスを左上とする縦 9 マス 横 9 マスの領域は以下のようになっており、TaK Code の条件を満たします。
###...... ###...... ###...... ......... ..##..... ..##..... ......### ......### ......###
入力例 2
9 21 ###.#...........#.### ###.#...........#.### ###.#...........#.### ....#...........#.... #########...######### ....#...........#.... ....#.###...###.#.... ....#.###...###.#.... ....#.###...###.#....
出力例 2
1 1
入力例 3
18 18 ######............ ######............ ######............ ######............ ######............ ######............ .................. .................. .................. .................. .................. .................. ............###### ............###### ............###### ............###### ............###### ............######
出力例 3
TaK Code の条件を満たす箇所が 1 つもないこともあります。
Score : 200 points
Problem Statement
Takahashi invented Tak Code, a two-dimensional code. A TaK Code satisfies all of the following conditions:
- It is a region consisting of nine horizontal rows and nine vertical columns.
- All the 18 cells in the top-left and bottom-right three-by-three regions are black.
- All the 14 cells that are adjacent (horizontally, vertically, or diagonally) to the top-left or bottom-right three-by-three region are white.
It is not allowed to rotate a TaK Code.
You are given a grid with N horizontal rows and M vertical columns.
The state of the grid is described by N strings, S_1,\ldots, and S_N, each of length M. The cell at the i-th row from the top and j-th column from the left is black if the j-th character of S_i is #, and white if it is ..
Find all the nine-by-nine regions, completely contained in the grid, that satisfy the conditions of a TaK Code.
Constraints
- 9 \leq N,M \leq 100
- N and M are integers.
- S_i is a string of length M consisting of
.and#.
Input
The input is given from Standard Input in the following format:
N M S_1 \vdots S_N
Output
For all pairs (i,j) such that the nine-by-nine region, whose top-left cell is at the i-th row from the top and j-th columns from the left, satisfies the conditions of a TaK Code, print a line containing i, a space, and j in this order.
The pairs must be sorted in lexicographical ascending order; that is, i must be in ascending order, and within the same i, j must be in ascending order.
Sample Input 1
19 18 ###......###...... ###......###...... ###..#...###..#... ..............#... .................. .................. ......###......### ......###......### ......###......### .###.............. .###......##...... .###.............. ............###... ...##.......###... ...##.......###... .......###........ .......###........ .......###........ ........#.........
Sample Output 1
1 1 1 10 7 7 10 2
A TaK Code looks like the following, where # is a black cell, . is a white cell, and ? can be either black or white.
###.????? ###.????? ###.????? ....????? ????????? ?????.... ?????.### ?????.### ?????.###
In the grid given by the input, the nine-by-nine region, whose top-left cell is at the 10-th row from the top and 2-nd column from the left, satisfies the conditions of a TaK Code, as shown below.
###...... ###...... ###...... ......... ..##..... ..##..... ......### ......### ......###
Sample Input 2
9 21 ###.#...........#.### ###.#...........#.### ###.#...........#.### ....#...........#.... #########...######### ....#...........#.... ....#.###...###.#.... ....#.###...###.#.... ....#.###...###.#....
Sample Output 2
1 1
Sample Input 3
18 18 ######............ ######............ ######............ ######............ ######............ ######............ .................. .................. .................. .................. .................. .................. ............###### ............###### ............###### ............###### ............###### ............######
Sample Output 3
There may be no region that satisfies the conditions of TaK Code.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
りんご市場に N 人の売り手と M 人の買い手がいます。
i 番目の売り手は、A_i 円以上でならりんごを売ってもよいと考えています。
i 番目の買い手は、B_i 円以下でならりんごを買ってもよいと考えています。
次の条件を満たすような最小の整数 X を求めてください。
条件:りんごを X 円で売ってもよいと考える売り手の人数が、りんごを X 円で買ってもよいと考える買い手の人数以上である。
制約
- 1 \leq N,M \leq 2\times 10^5
- 1\leq A_i,B_i \leq 10^9
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 \ldots A_N B_1 \ldots B_M
出力
答えを出力せよ。
入力例 1
3 4 110 90 120 100 80 120 10000
出力例 1
110
りんごを 110 円で売ってもよいと考える売り手は 1,2 番目の 2 人であり、りんごを 110 円で買ってもよいと考える買い手は 3,4 番目の 2 人であるため、110 は条件を満たします。
110 未満の整数が条件を満たすことはないため、これが答えです。
入力例 2
5 2 100000 100000 100000 100000 100000 100 200
出力例 2
201
入力例 3
3 2 100 100 100 80 120
出力例 3
100
Score : 300 points
Problem Statement
There are N sellers and M buyers in an apple market.
The i-th seller may sell an apple for A_i yen or more (yen is the currency in Japan).
The i-th buyer may buy an apple for B_i yen or less.
Find the minimum integer X that satisfies the following condition.
Condition: The number of people who may sell an apple for X yen is greater than or equal to the number of people who may buy an apple for X yen.
Constraints
- 1 \leq N,M \leq 2\times 10^5
- 1\leq A_i,B_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 \ldots A_N B_1 \ldots B_M
Output
Print the answer.
Sample Input 1
3 4 110 90 120 100 80 120 10000
Sample Output 1
110
Two sellers, the 1-st and 2-nd, may sell an apple for 110 yen; two buyers, the 3-rd and 4-th, may buy an apple for 110 yen. Thus, 110 satisfies the condition.
Since an integer less than 110 does not satisfy the condition, this is the answer.
Sample Input 2
5 2 100000 100000 100000 100000 100000 100 200
Sample Output 2
201
Sample Input 3
3 2 100 100 100 80 120
Sample Output 3
100
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
空でない文字列 S が与えられます。S の各文字は (, ), ? のいずれかです。
S に含まれる ? の個数を x とすると、? を ( あるいは ) に置き換えて新しい文字列を作る方法は 2^x 通りありますが、このうち新しくできた文字列が括弧列となるような置き換え方の数を 998244353 で割った余りを求めてください。
ただし、括弧列とは以下のいずれかの条件を満たす文字列のことです。
- 空文字列
- ある括弧列 A が存在して、
(, A,)をこの順に連結した文字列 - ある空でない括弧列 A, B が存在して、A, B をこの順に連結した文字列
制約
- S は長さ 3000 以下の
(,),?からなる空でない文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
(???(?
出力例 1
2
S を ()()() あるいは (())() に置き換えると括弧列となります。
他の置き換え方で新しくできた文字列が括弧列となることはないので、2 を出力します。
入力例 2
)))))
出力例 2
0
入力例 3
??????????????(????????(??????)?????????(?(??)
出力例 3
603032273
998244353 で割った余りを出力してください。
Score : 400 points
Problem Statement
You are given a non-empty string S consisting of (, ), and ?.
There are 2^x ways to obtain a new string by replacing each ? in S with ( and ), where x is the number of occurrences of ? in S. Among them, find the number, modulo 998244353, of ways that yield a parenthesis string.
A string is said to be a parenthesis string if one of the following conditions is satisfied.
- It is an empty string.
- It is a concatenation of
(, A, and), for some parenthesis string A. - It is a concatenation of A and B, for some non-empty parenthesis strings A and B.
Constraints
- S is a non-empty string of length at most 3000 consisting of
(,), and?.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
(???(?
Sample Output 1
2
Replacing S with ()()() or (())() yields a parenthesis string.
The other replacements do not yield a parenthesis string, so 2 should be printed.
Sample Input 2
)))))
Sample Output 2
0
Sample Input 3
??????????????(????????(??????)?????????(?(??)
Sample Output 3
603032273
Print the count modulo 998244353.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
3 次元空間内に N 個の直方体があります。
直方体同士は重なっていません。厳密には、相異なるどの 2 つの直方体の共通部分の体積も 0 です。
i 番目の直方体は、2 点 (X_{i,1},Y_{i,1},Z_{i,1}), (X_{i,2},Y_{i,2},Z_{i,2}) を結ぶ線分を対角線とし、辺は全ていずれかの座標軸に平行です。
各直方体について、他のいくつの直方体と面で接しているか求めてください。
厳密には、各 i に対し、1\leq j \leq N かつ j\neq i である j のうち、i 番目の直方体の表面と j 番目の直方体の表面の共通部分の面積が正であるものの個数を求めてください。
制約
- 1 \leq N \leq 10^5
- 0 \leq X_{i,1} < X_{i,2} \leq 100
- 0 \leq Y_{i,1} < Y_{i,2} \leq 100
- 0 \leq Z_{i,1} < Z_{i,2} \leq 100
- 直方体同士は体積が正の共通部分を持たない
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N
X_{1,1} Y_{1,1} Z_{1,1} X_{1,2} Y_{1,2} Z_{1,2}
\vdots
X_{N,1} Y_{N,1} Z_{N,1} X_{N,2} Y_{N,2} Z_{N,2}
出力
答えを出力せよ。
入力例 1
4 0 0 0 1 1 1 0 0 1 1 1 2 1 1 1 2 2 2 3 3 3 4 4 4
出力例 1
1 1 0 0
1 番目の直方体と 2 番目の直方体は、2 点 (0,0,1),(1,1,1) を結ぶ線分を対角線とする長方形を共有しています。
1 番目の直方体と 3 番目の直方体は、点 (1,1,1) を共有していますが、面で接してはいません。
入力例 2
3 0 0 10 10 10 20 3 4 1 15 6 10 0 9 6 1 20 10
出力例 2
2 1 1
入力例 3
8 0 0 0 1 1 1 0 0 1 1 1 2 0 1 0 1 2 1 0 1 1 1 2 2 1 0 0 2 1 1 1 0 1 2 1 2 1 1 0 2 2 1 1 1 1 2 2 2
出力例 3
3 3 3 3 3 3 3 3
Score : 500 points
Problem Statement
There are N rectangular cuboids in a three-dimensional space.
These cuboids do not overlap. Formally, for any two different cuboids among them, their intersection has a volume of 0.
The diagonal of the i-th cuboid is a segment that connects two points (X_{i,1},Y_{i,1},Z_{i,1}) and (X_{i,2},Y_{i,2},Z_{i,2}), and its edges are all parallel to one of the coordinate axes.
For each cuboid, find the number of other cuboids that share a face with it.
Formally, for each i, find the number of j with 1\leq j \leq N and j\neq i such that the intersection of the surfaces of the i-th and j-th cuboids has a positive area.
Constraints
- 1 \leq N \leq 10^5
- 0 \leq X_{i,1} < X_{i,2} \leq 100
- 0 \leq Y_{i,1} < Y_{i,2} \leq 100
- 0 \leq Z_{i,1} < Z_{i,2} \leq 100
- Cuboids do not have an intersection with a positive volume.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
X_{1,1} Y_{1,1} Z_{1,1} X_{1,2} Y_{1,2} Z_{1,2}
\vdots
X_{N,1} Y_{N,1} Z_{N,1} X_{N,2} Y_{N,2} Z_{N,2}
Output
Print the answer.
Sample Input 1
4 0 0 0 1 1 1 0 0 1 1 1 2 1 1 1 2 2 2 3 3 3 4 4 4
Sample Output 1
1 1 0 0
The 1-st and 2-nd cuboids share a rectangle whose diagonal is the segment connecting two points (0,0,1) and (1,1,1).
The 1-st and 3-rd cuboids share a point (1,1,1), but do not share a surface.
Sample Input 2
3 0 0 10 10 10 20 3 4 1 15 6 10 0 9 6 1 20 10
Sample Output 2
2 1 1
Sample Input 3
8 0 0 0 1 1 1 0 0 1 1 1 2 0 1 0 1 2 1 0 1 1 1 2 2 1 0 0 2 1 1 1 0 1 2 1 2 1 1 0 2 2 1 1 1 1 2 2 2
Sample Output 3
3 3 3 3 3 3 3 3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
N 個の品物があります。
これらはそれぞれ、缶切りが不要な缶・缶切りが必要な缶・缶切りのいずれかです。
i 個目の品物は、整数の組 (T_i, X_i) により次のように表されます。
- T_i = 0 ならば、i 個目の品物は缶切りが不要な缶で、入手すると満足度 X_i を得る。
- T_i = 1 ならば、i 個目の品物は缶切りが必要な缶で、入手した上で缶切りを使うと満足度 X_i を得る。
- T_i = 2 ならば、i 個目の品物は缶切りで、X_i 個までの缶に対して使用できる。
N 個の品物から M 個を選んで入手するとき、得られる満足度の合計としてあり得る最大値を求めてください。
制約
- 1 \leq M \leq N \leq 2 \times 10^5
- T_i は 0,1,2 のいずれか
- 1 \leq X_i \leq 10^9
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M T_1 X_1 T_2 X_2 \vdots T_N X_N
出力
答えを整数として出力せよ。
入力例 1
8 4 0 6 0 6 1 3 1 5 1 15 2 1 2 10 2 100
出力例 1
27
1, 2, 5, 7 個目の品物を入手し、7 個目の品物である缶切りを 5 個目の品物に対して使用すると、満足度 6 + 6 + 15 = 27 を得ます。
満足度が 28 以上になる品物の入手方法は存在しませんが、上記の例において 7 個目の品物のかわりに 6 個目の品物や 8 個目の品物を選んでも満足度 27 を得ることができます。
入力例 2
5 5 1 5 1 5 1 5 1 5 1 5
出力例 2
0
入力例 3
12 6 2 2 0 1 0 9 1 3 1 5 1 3 0 4 2 1 1 8 2 1 0 1 0 4
出力例 3
30
Score : 500 points
Problem Statement
There are N items.
Each of these is one of a pull-tab can, a regular can, or a can opener.
The i-th item is described by an integer pair (T_i, X_i) as follows:
- If T_i = 0, the i-th item is a pull-tab can; if you obtain it, you get a happiness of X_i.
- If T_i = 1, the i-th item is a regular can; if you obtain it and use a can opener against it, you get a happiness of X_i.
- If T_i = 2, the i-th item is a can opener; it can be used against at most X_i cans.
Find the maximum total happiness that you get by obtaining M items out of N.
Constraints
- 1 \leq M \leq N \leq 2 \times 10^5
- T_i is 0, 1, or 2.
- 1 \leq X_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M T_1 X_1 T_2 X_2 \vdots T_N X_N
Output
Print the answer as an integer.
Sample Input 1
8 4 0 6 0 6 1 3 1 5 1 15 2 1 2 10 2 100
Sample Output 1
27
If you obtain the 1-st, 2-nd, 5-th, and 7-th items, and use the 7-th item (a can opener) against the 5-th item, you will get a happiness of 6 + 6 + 15 = 27.
There are no ways to obtain items to get a happiness of 28 or greater, but you can still get a happiness of 27 by obtaining the 6-th or 8-th items instead of the 7-th in the combination above.
Sample Input 2
5 5 1 5 1 5 1 5 1 5 1 5
Sample Output 2
0
Sample Input 3
12 6 2 2 0 1 0 9 1 3 1 5 1 3 0 4 2 1 1 8 2 1 0 1 0 4
Sample Output 3
30
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
N 頂点の木が与えられます。頂点には 1 から N までの番号がついており、i 番目の辺は頂点 A_i と頂点 B_i を結んでいます。
以下の条件を満たす整数の組 (i,j,k) の個数を求めてください。
- 1 \leq i < j < k \leq N
- 与えられた木には頂点 i,j,k をすべて含む単純パスは存在しない
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq N
- 与えられるグラフは木
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
A_1 B_1
\vdots
A_{N-1} B_{N-1}
出力
答えを出力せよ。
入力例 1
5 1 2 2 3 2 4 1 5
出力例 1
2
(i,j,k) = (1,3,4),(3,4,5) の 2 つが条件を満たします。
入力例 2
6 1 2 2 3 3 4 4 5 5 6
出力例 2
0
入力例 3
12 1 6 3 4 10 4 5 9 3 1 2 3 7 2 2 12 1 5 6 8 4 11
出力例 3
91
Score : 550 points
Problem Statement
You are given a tree with N vertices. The vertices are numbered from 1 through N, and the i-th edge connects vertex A_i and vertex B_i.
Find the number of tuples of integers (i,j,k) such that:
- 1 \leq i < j < k \leq N; and
- the given tree does not contain a simple path that contains all of vertices i, j, and k.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq N
- The given graph is a tree.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1 B_1
\vdots
A_{N-1} B_{N-1}
Output
Print the answer.
Sample Input 1
5 1 2 2 3 2 4 1 5
Sample Output 1
2
Two tuples satisfy the conditions: (i,j,k) = (1,3,4),(3,4,5).
Sample Input 2
6 1 2 2 3 3 4 4 5 5 6
Sample Output 2
0
Sample Input 3
12 1 6 3 4 10 4 5 9 3 1 2 3 7 2 2 12 1 5 6 8 4 11
Sample Output 3
91
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 600 点
問題文
高橋君は人 1,\ldots,N の N 人のあだ名を決めることになりました。
人 i はあだ名を S_i にしてほしいと思っています。複数人に同じあだ名をつけるのを避けるため、高橋君は次の手順で N 人のあだ名を決めることにしました。
- i=1,\ldots,N の順に、以下の操作により人 i のあだ名を決める
- 変数 k_i を 1 とする。
- 「S_i を k_i 回繰り返した文字列」がすでに誰かのあだ名である間、k_i を 1 増やすことを繰り返す。
- 「S_i を k_i 回繰り返した文字列」を人 i のあだ名とする。
N 人のあだ名を決めた後の k_1,\ldots,k_N を求めてください。
制約
- N \geq 1
- S_i は英小文字のみからなる、長さ 1 以上の文字列
- S_i の長さの総和は 2\times 10^5 以下
入力
入力は以下の形式で標準入力から与えられる。
N S_1 \vdots S_N
出力
問題文中の操作により N 人のあだ名を決めた後の k_1,\ldots,k_N をこの順に空白区切りで出力せよ。
入力例 1
3 snuke snuke rng
出力例 1
1 2 1
- まず人 1 のあだ名を決めます。
- k_1=1 とします。
- S_1 を k_1 回繰り返した文字列
snukeは誰のあだ名でもないので、人 1 のあだ名はsnukeになります。
- 次に人 2 のあだ名を決めます。
- k_2=1 とします。
- S_2 を k_2 回繰り返した文字列
snukeはすでに人 1 のあだ名なので、k_2 を 1 増やして 2 とします。 - S_2 を k_2 回繰り返した文字列
snukesnukeは誰のあだ名でもないので、人 2 のあだ名はsnukesnukeになります。
- 最後に人 3 のあだ名を決めます。
- k_3=1 とします。
- S_3 を k_3 回繰り返した文字列
rngは誰のあだ名でもないので、人 3 のあだ名はrngになります。
以上により、k_1,k_2,k_3 はそれぞれ 1,2,1 となります。
入力例 2
4 aa a a aaa
出力例 2
1 1 3 2
- 人 1 のあだ名は
aaになります。 - 人 2 のあだ名は
aになります。 - 人 3 のあだ名は、
a,aaがすでに他の人のあだ名なので、aaaになります。 - 人 4 のあだ名は、
aaaがすでに他の人のあだ名なので、aaaaaaになります。
入力例 3
5 x x x x x
出力例 3
1 2 3 4 5
Score : 600 points
Problem Statement
Takahashi is going to decide nicknames of N people, person 1,\ldots,N.
Person i wants a nickname S_i. To avoid giving the same nickname to multiple people, he is going to decide their nicknames as follows:
- For each i=1,\ldots,N in order, decide person i's nickname as follows:
- Initialize a variable k_i with 1.
- Repeatedly increment k_i by one while the k_i-time repetition of S_i is someone's nickname.
- Let person i's nickname be the k_i-time repetition of S_i.
Find k_1,\ldots, and k_N after deciding nicknames of the N people.
Constraints
- N \geq 1
- S_i is a string of length at least 1 consisting of lowercase English letters.
- The sum of lengths of S_i is at most 2\times 10^5.
Input
The input is given from Standard Input in the following format:
N S_1 \vdots S_N
Output
Print k_1,\ldots, and k_N resulting from deciding the nicknames of the N people by the procedure in the problem statement.
Sample Input 1
3 snuke snuke rng
Sample Output 1
1 2 1
- First, he decides person 1's nickname.
- Let k_1=1.
- The k_1-time repetition of S_1 is
snuke, which is nobody's nickname, so person 1's nickname is set tosnuke.
- Next, he decides person 2's nickname.
- Let k_2=1.
- The k_2-time repetition of S_2 is
snuke, which is already a nickname of person 1, so increment k_2 by one to make it 2. - The k_2-time repetition of S_2 is
snukesnuke, which is nobody's nickname, so person 2's nickname is set tosnukesnuke.
- Finally, he decides person 3's nickname.
- Let k_3=1.
- The k_3-time repetition of S_3 is
rng, which is nobody's nickname, so person 3's nickname is set torng.
Thus, k_1, k_2, and k_3 result in 1, 2, and 1, respectively.
Sample Input 2
4 aa a a aaa
Sample Output 2
1 1 3 2
- Person 1's nickname is set to
aa. - Person 2's nickname is set to
a. - Person 3's nickname is set to
aaa, becauseaandaaare already nicknames of someone else. - Person 4's nickname is set to
aaaaaa, becauseaaais already a nickname of someone else.
Sample Input 3
5 x x x x x
Sample Output 3
1 2 3 4 5