Under construction

Still being built. Things may change

Frequent

Time limit0.5sMemory limit1024 MB

Summary
Given K DNA strings with total length N, find for each i from 2 to K the longest substring shared by at least i of the strings.
Level

Medium7 of 10

Topics
String matching, Sliding window, Sorting
Solved
No attempts yet

Problem

An astrobiologist studies life on the planet Alphabet. Life there is DNA-based, and there are 26 nucleotides. So the DNA of a life form from Alphabet is a string of lowercase Latin letters. The astrobiologist has sequenced the DNA of KK life forms. The DNA strings are not necessarily distinct, and their total length is NN nucleotides. She wants to find the strands (substrings) of DNA that occur frequently among these life forms. Let L(i)L(i) be the length of the longest strand of consecutive nucleotides that is common to at least ii life forms, for 2≤i≤K2 \le i \le K. L(i)L(i) can be 0.

Help the astrobiologist compute the array LL.

Input

The first line contains an integer KK, the number of life forms. Each of the next KK lines contains a non-empty string of lowercase letters.

Output

Print K−1K - 1 lines with the values L(2),L(3),…,L(K)L(2), L(3), \ldots, L(K), one value per line.

Constraints

2≤N≤200,0002 \le N \le 200{,}000

2≤K≤N2 \le K \le N

Hints

"atter" appears in two of the strings.

"mat" appears in three of the strings.

"ma" (or "at" or "te") appears in four of the strings.

"ma" appears in five of the strings.

"a" appears in all the strings.

Examples1

  1. Example 1

    Input
    6
    matter
    animate
    pattern
    thermal
    domain
    teammate
    
    Expected output
    5
    3
    2
    2
    1