Registration system

4.3

17 votes
Problem

Your task is to write a registration system.

The system works in the following way. Every user has a preferred login li. System finds the first free login considering possible logins in the following order: li, li0, li1, li2, ... , li10, li11, ... (you check li first; in case it is occupied already, you pick smallest nonnegative integer x such that concatenation of li and decimal notation of x gives you free login) and register a user with this login in the system. After the registration this login becomes occupied.

You gave the preferred logins for the n users in chronological order. For each user you have to find a login which he will use in the system.

INPUT

The first line of input contains a single integer n (1n2105) - a number of users.

Then follow n lines. The i-th of these lines contains li - a preferred login for i-th user. li is a nonempty string with lowercase english letters and digits.

Guaranteed that the sum of lengths of li is not greater than 106.

OUTPUT

Print n lines. The i-th of these lines should contain an occupied login for the i-th user.

Time Limit: 1
Memory Limit: 512
Source Limit:
Explanation

Logins for the first three users are free. Fourth user want to use login "lebron" but the first login which isn't occupied is "lebron2".

Editor Image

?