#abc312h. Ex - snukesnuke

Ex - snukesnuke

Score : 600600 points

问题描述

高桥打算为 NN 个人(编号为 1,…,N)确定他们的昵称。

ii 个人希望得到的昵称为 SiS_i。为了避免给多人分配相同的昵称,他将按照以下方式决定每个人的昵称:

  • 对于 i=1,,Ni=1,\ldots,N 按顺序执行以下操作:
    • 将变量 kik_i 初始化为 11
    • SiS_i 的第 kik_i 次重复作为某人的昵称时,不断将 kik_i 加一。
    • 将第 ii 个人的昵称设为 SiS_i 的第 kik_i 次重复。

请在确定这 NN 个人的昵称后,找出 k1,,kNk_1,\ldots,k_N 的值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi is going to decide nicknames of NN people, person 1,,N1,\ldots,N.

Person ii wants a nickname SiS_i. To avoid giving the same nickname to multiple people, he is going to decide their nicknames as follows:

  • For each i=1,,Ni=1,\ldots,N in order, decide person ii's nickname as follows:
    • Initialize a variable kik_i with 11.
    • Repeatedly increment kik_i by one while the kik_i-time repetition of SiS_i is someone's nickname.
    • Let person ii's nickname be the kik_i-time repetition of SiS_i.

Find k1,k_1,\ldots, and kNk_N after deciding nicknames of the NN people.

Constraints

  • N1N \geq 1
  • SiS_i is a string of length at least 11 consisting of lowercase English letters.
  • The sum of lengths of SiS_i is at most 2×1052\times 10^5.

Input

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

NN

S1S_1

\vdots

SNS_N

Output

Print k1,k_1,\ldots, and kNk_N resulting from deciding the nicknames of the NN 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 11's nickname.
    • Let k1=1k_1=1.
    • The k1k_1-time repetition of S1S_1 is snuke, which is nobody's nickname, so person 11's nickname is set to snuke.
  • Next, he decides person 22's nickname.
    • Let k2=1k_2=1.
    • The k2k_2-time repetition of S2S_2 is snuke, which is already a nickname of person 11, so increment k2k_2 by one to make it 22.
    • The k2k_2-time repetition of S2S_2 is snukesnuke, which is nobody's nickname, so person 22's nickname is set to snukesnuke.
  • Finally, he decides person 33's nickname.
    • Let k3=1k_3=1.
    • The k3k_3-time repetition of S3S_3 is rng, which is nobody's nickname, so person 33's nickname is set to rng.

Thus, k1k_1, k2k_2, and k3k_3 result in 11, 22, and 11, respectively.

Sample Input 2

4
aa
a
a
aaa

Sample Output 2

1 1 3 2
  • Person 11's nickname is set to aa.
  • Person 22's nickname is set to a.
  • Person 33's nickname is set to aaa, because a and aa are already nicknames of someone else.
  • Person 44's nickname is set to aaaaaa, because aaa is already a nickname of someone else.

Sample Input 3

5
x
x
x
x
x

Sample Output 3

1 2 3 4 5

update @ 2024/3/10 08:54:29