Mirror IIOT 2022-2023, Final Round | phonebook

This was the problem page during the contest. Access the current page here.
Time limit: 1s
Memory limit: 128MB
Input:
Output:

Task

Your friend, Ursu, gave a list of NN words only containing lowercase letters of the English alphabet. The list represents Ursu's phone book. Unfortunately, Ursu's phone book is quite long. That is why he would like you to help him rename all his contacts. Since both of you are quite lazy, you want to minimize the time spent renaming all the contacts. Now, Ursu asks you to find for each of the NN words the length of its shortest substring that does not appear in any of the other strings. If no such substring exists, Ursu would like to know that he cannot rename that contact, so, the answer will be considered to be 1-1.

Input

The first line of the input contains the number NN (1N21051 \le N \le 2 * 10^5). The next NN lines will each contain a string SS.

The total length of all the strings (noted SS) will be at most 21052 * 10^5

For tests worth 1313 points, 1S1001 \le S \le 100.

For tests worth 5454 more points, 1S21041 \le S \le 2 * 10^4.

Output

The program will print NN lines, the ithi-th of them representing the length of the shortest substring of the ithi-th string not appearing in any other string.

Example 1

stdin

3
abdf
abf
abde

stdout

2
2
1

Contest info

Official contest

Start time: 1677902400000

Total duration: 209h59m0s

Status: Ended

Individual duration: 3h0m0s

Log in or sign up to be able to send submissions!