409448: GYM103562 C Cinder

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Cindertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

With Valentine's Day just around the corner, Sophie is ready to release her new dating app, Cinder. She assigns you the job of writing the program to generate usernames for each new person who registers for the app based on their given name. Sophie is very particular about her app so she asks for the following scheme for the usernames:

Each time a user registers, the system is sent a request with their name (call this string $$$s$$$). If $$$s$$$ is not yet in the database, it is inserted into the database and the user gets the response OK to signify that they were able to register. If $$$s$$$ is already in the database, the system will create a new string $$$s'$$$ and insert $$$s'$$$ into the database before returning $$$s'$$$ back to the user as their new username. The string $$$s'$$$ is formed by adding a number to the end of $$$s$$$ (so $$$s$$$, $$$s1$$$, $$$s2$$$, $$$s3$$$ ...) where each time the number $$$i$$$ appended is the smallest positive integer such that $$$s'$$$ = $$$s$$$ + $$$i$$$ is not already in the system.

Given $$$n$$$ users, implement a program that will return the right username for each person (or OK if the name wasn't in the system already).

Input

The first line will contain a single integer $$$n$$$ (where $$$1 \leq n \leq 10^{5}$$$) representing the number of new users (aka incoming requests),

The following $$$n$$$ lines will each contain a request (name of the new user) in the order the system gets the requests. Each request is a non-empty string consisting of only lowercase letters and will not be longer than $$$32$$$ characters.

Output

For each of the $$$n$$$ request lines, print the system response (so OK if the name wasn't in the database already or the new username if it was already there).

ExamplesInput
4
marta
mia
mia
alexia
Output
OK
OK
mia1
OK
Input
6
weston
mohamed
gabriel
weston
mohamed
gabriel
Output
OK
OK
OK
weston1
mohamed1
gabriel1

加入题单

上一题 下一题 算法标签: