C - NewFolder(1) Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

2 つの文字列 A,B に対して、A の末尾に B を連結した文字列を A+B と表します。

N 個の文字列 S_1,\ldots,S_N が与えられます。i=1,\ldots,N の順に、次の指示に従って加工して出力してください。

  • S_1,\ldots,S_{i-1} の中に S_i と同じ文字列が存在しないならば、S_i を出力する。
  • S_1,\ldots,S_{i-1} の中に S_i と同じ文字列が X(X>0) 存在するならば、X を文字列として扱って S_i+ ( +X+ ) を出力する。

制約

  • 1 \leq N \leq 2\times 10^5
  • S_i は英小文字のみからなる長さ 1 以上 10 以下の文字列

入力

入力は以下の形式で標準入力から与えられる。

N
S_1
S_2
\vdots
S_N

出力

問題文中の指示にしたがって、N 行出力せよ。


入力例 1

5
newfile
newfile
newfolder
newfile
newfolder

出力例 1

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

入力例 2

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

出力例 2

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

Score : 300 points

Problem Statement

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

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

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

Constraints

  • 1 \leq N \leq 2\times 10^5
  • S_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S_1
S_2
\vdots
S_N

Output

Print N 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)