Технокубок 2021 - Финал
H
Exam
Codeforces
3400
原题
← G→
翻译中…

This year a Chunin Selection Exam is held again in Konoha, and taking part in it are $n$ ninjas named $s_1$, $s_2$, ..., $s_n$. All names are distinct. One of the exam stages consists of fights between the participants. This year the rules determining the ninjas for each fight are the following: ninjas $i$ and $j$ fight against each other if the following conditions are held:

翻译中…
  • $i \neq j$;
  • $s_{j}$ is a substring of $s_{i}$;
  • there is no $k$ except $i$ and $j$ that $s_{j}$ is a substring of $s_{k}$, and $s_{k}$ is a substring of $s_{i}$.
翻译中…

A string $a$ is a substring of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

翻译中…

Your task is to find out how many fights are going to take place this year.

翻译中…

Input

翻译中…

The first line consists of the only integer $n$ ($1 \leq n \leq 10^{6}$) standing for the number of examinees.

翻译中…

The following $n$ lines contain their names. No two names coincide, all names are non-empty and consist of lowercase English letters. The total length of all names doesn't exceed $10^6$.

翻译中…

Output

翻译中…

Print the only integer standing for the number of fights.

翻译中…

Note

翻译中…

In the first example hidan fights against dan, and hanabi fights against nabi, who also fights bi. Ninjas named hanabi and bi don't fight each other since there is the ninja called nabi who breaks the third condition for them.

翻译中…

In the second example the fights are held between abacaba and acaba, abacaba and abaca, acaba and aca, abaca and aca.

翻译中…

样例

Input #1
5
hidan
dan
hanabi
bi
nabi
Output #1
3
InputCopy OutputCopy
Input #2
4
abacaba
abaca
acaba
aca
Output #2
4
InputCopy OutputCopy
题目信息
题号
1482H
时间限制
2 s
内存限制
512 MB
标签
数据结构
后缀结构
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。