#P4081. Cow Name Uniqueness

    ID: 17329 Type: Default 1000ms 256MiB

Cow Name Uniqueness

Cow Name Uniqueness

Cows like to feel unique. In this problem, each cow's name gives rise to a set of substrings. For example, the name "amy" has the substrings \(\{a, m, y, am, my, amy\}\). The uniqueness factor of a cow is defined as the number of substrings in its name that do not appear in any other cow's name.

If a cow is alone in the herd, its uniqueness factor is simply the total number of substrings of its name. However, when there are multiple cows, some substrings might be shared among names. Your task is to compute the uniqueness factor for each cow in the herd.

Note: A substring is a contiguous sequence of characters in a string.

inputFormat

The first line contains a single integer \(N\) representing the number of cows. The following \(N\) lines each contain a cow's name consisting of lowercase letters only.

Example:

2
amy
tommy

outputFormat

Output \(N\) lines, each containing the uniqueness factor of the corresponding cow from the input, in the same order.

Example:

3
11

sample

1
amy
6

</p>