Registration system

0

0 votes
Trie, Medium, Data Structures
Problem

Your task is to write a registration system.

The system works in the following way. Every user has a preferred login . System finds the first free login considering possible logins in the following order: , , , , ... , , , ... (you check first; in case it is occupied already, you pick smallest nonnegative integer x such that concatenation of 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.

The first line of input contains a single integer n - a number of users.

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

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

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

Sample Input
4
lebron
lebron0
lebron1
lebron
Sample Output
lebron
lebron0
lebron1
lebron2
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

?