#x1037. CF1483F Exam
CF1483F Exam
Exam
题面翻译
给定互不相同的字符串 ,求有多少对 满足:
- 是 的子串。
- 不存在 满足 是 的子串且 是 的子串。
保证 。
我们规定 是 的字串仅当通过将 从前和后删除若干个(当然可以是零个或所有)字符可以得到 。
对于样例一, 满足要求。
对于样例二, 满足要求。
题目描述
This year a Chunin Selection Exam is held again in Konoha, and taking part in it are ninjas named , , ..., . 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 and fight against each other if the following conditions are held:
- ;
- is a substring of ;
- there is no except and that is a substring of , and is a substring of .
A string is a substring of a string if can be obtained from 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.
输入格式
The first line consists of the only integer ( ) standing for the number of examinees.
The following 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 .
输出格式
Print the only integer standing for the number of fights.
样例 #1
样例输入 #1
5
hidan
dan
hanabi
bi
nabi
样例输出 #1
3
样例 #2
样例输入 #2
4
abacaba
abaca
acaba
aca
样例输出 #2
4
提示
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.