Under construction

Still being built. Things may change

List

Time limit2sMemory limit1024 MB

Summary
Given n names, count for each length x the pairs whose length-x prefixes and length-x suffixes are both equal.
Level

Medium7 of 10

Topics
Trie, String, Hash map
Solved
No attempts yet

Problem

Scientists recently found a complete list of all worlds that existed before the first humans appeared on Earth. They want to collect some statistics from it, so they define when two names are similar.

Two names are called xx-similar if their suffixes of length xx are equal and their prefixes of length xx are equal.

The prefix of length xx of a string is its first xx characters. The suffix of length xx is its last xx characters. Taking a prefix or suffix longer than the string is an invalid operation.

For every integer xx from 1 to the maximum length of a name in the list, find the number of pairs of names that are xx-similar.

Input

The first line contains one integer nn (1≤n≤1051 \le n \le 10^5), the number of names. Each of the next nn lines contains one name. The total length of all names does not exceed 500 000500\,000. Every name consists of lowercase Latin letters and has non-zero length.

Output

On the first line, print mm, the length of the longest name. On the line for xx (2≤x≤m+12 \le x \le m + 1), print the number of pairs of names that are (x−1)(x-1)-similar.

Examples1

  1. Example 1

    Input
    4
    aaaaaa
    abacaba
    aabaa
    aba
    
    Expected output
    7
    6
    2
    1
    0
    0
    0
    0