Frequent
Time limit0.5sMemory limit1024 MB
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 life forms. The DNA strings are not necessarily distinct, and their total length is nucleotides. She wants to find the strands (substrings) of DNA that occur frequently among these life forms. Let be the length of the longest strand of consecutive nucleotides that is common to at least life forms, for . can be 0.
Help the astrobiologist compute the array .
Input
The first line contains an integer , the number of life forms. Each of the next lines contains a non-empty string of lowercase letters.
Output
Print lines with the values , one value per line.
Constraints
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.