AtCoder Grand Contest 047
B
First Second
AtCoder
⌀ 1871
原题
← AC →
翻译中…

Problem Statement

翻译中…

Limak can repeatedly remove one of the first two characters of a string, for example $abcxyx \rightarrow acxyx \rightarrow cxyx \rightarrow cyx$.

翻译中…

You are given $N$ different strings $S_1, S_2, \ldots, S_N$. Among $N \cdot (N-1) / 2$ pairs $(S_i, S_j)$, in how many pairs could Limak obtain one string from the other?

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 200\,000$
  • $S_i$ consists of lowercase English letters a-z.
  • $S_i \neq S_j$
  • $1 \leq |S_i|$
  • $|S_1| + |S_2| + \ldots + |S_N| \leq 10^6$
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format.

翻译中…

N
S_1
S_2
\vdots
S_N

翻译中…

Output

翻译中…

Print the number of unordered pairs $(S_i, S_j)$ where $i \neq j$ and Limak can obtain one string from the other.

翻译中…

样例

Input #1
3
abcxyx
cyx
abc
Output #1
1
The only good pair is $(abcxyx, cyx)$.
Input #2
6
b
a
abc
c
d
ab
Output #2
5
There are five good pairs: $(b, abc)$, $(a, abc)$, $(abc, c)$, $(b, ab)$, $(a, ab)$.
题目信息
题号
agc047_b
时间限制
3 s
内存限制
1024 MB

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