#abc261c. C - NewFolder(1)

C - NewFolder(1)

Score : 300300 points

问题描述

对于两个字符串 AABB,令 A+BA+B 表示按顺序连接的 AABB

给定 NN 个字符串 S1,,SNS_1,\ldots,S_N。按照从 i=1i=1NN 的顺序修改并打印它们:

  • 如果 S1,,Si1S_1,\ldots,S_{i-1} 中没有一个等于 SiS_i,则打印 SiS_i
  • 如果有 XXX>0X>0)个 S1,,Si1S_1,\ldots,S_{i-1} 等于 SiS_i,则将 XX 视为字符串,打印 Si+S_i+ ( +X++X+ )

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

Problem Statement

For two strings AA and BB, let A+BA+B denote the concatenation of AA and BB in this order.

You are given NN strings S1,,SNS_1,\ldots,S_N. Modify and print them as follows, in the order i=1,,Ni=1, \ldots, N:

  • if none of S1,,Si1S_1,\ldots,S_{i-1} is equal to SiS_i, print SiS_i;
  • if XX (X>0)(X>0) of S1,,Si1S_1,\ldots,S_{i-1} are equal to SiS_i, print Si+S_i+ ( +X++X+ ), treating XX as a string.

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • SiS_i is a string of length between 11 and 1010 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

NN

S1S_1

S2S_2

\vdots

SNS_N

Output

Print NN lines as specified in the Problem Statement.

Sample Input 1

5
newfile
newfile
newfolder
newfile
newfolder

Sample Output 1

newfile
newfile(1)
newfolder
newfile(2)
newfolder(1)

Sample Input 2

11
a
a
a
a
a
a
a
a
a
a
a

Sample Output 2

a
a(1)
a(2)
a(3)
a(4)
a(5)
a(6)
a(7)
a(8)
a(9)
a(10)

update @ 2024/3/10 11:03:38