Progressive NoSQL
InterviewTime limit2sMemory limit1024 MB
Given Q registration requests, each name is assigned as-is if free, otherwise the smallest suffix number (1, 2, ...) that makes it unused is appended.
Problem
<> is a progressive IT company that develops a social network with the same name. Vanya recently joined the company. His current task is to implement a database that tracks new user registrations. Vanya is preparing for the ICPC quarterfinal, so he needs your help.
The database is initially empty. Over time, people each send one request to the database. Each request is a non-empty string of uppercase and lowercase English letters and digits, with length at most 10. If no user with that name exists in the system, register a user with that name. Otherwise, append 1 to the name and check whether a user with that name exists. If not, register a user with the name ending in 1. If it does exist, append 2 instead of 1, then append 3 instead of 2 if that name is also taken, and so on. The answer to each request is the name the user received.
Input
The first line contains the number (), the number of requests. The requests are given in chronological order.
Each of the next lines contains a non-empty string. The string contains only uppercase and lowercase English letters and digits. Its length does not exceed 10.
Output
Print lines. The -th line is the name that the -th user received.