cswork / OA打开练习工作台

UberOA #65

Word Pairs

估计中等可在线判题

考点(AI 标注)字典树序列化哈希计数

Count unordered pairs of distinct indices i<j such that the two words are equal, or one is a prefix of the other. Identical words at different indices are still counted separately.

This site has made the standard input and output explicit.

输入格式

The first line contains n, followed by n words. The source gives no character or length bounds; on this site 1≤n≤100000, and words contain only lowercase English letters with length 1..30.

输出格式

Output one integer, the answer.

样例 1

输入:

7
back
backdoor
gammon
backgammon
comeback
come
door

输出:

3

样例 2

输入:

6
abc
a
a
b
ab
ac

输出:

8

样例 3

输入:

3
x
x
x

输出:

3

样例说明

Example 1: back pairs with backdoor and backgammon, 2 pairs, and come pairs with comeback, 1 pair, for 3 in total. Example 2: the two a's form 1 pair with each other, and each forms pairs with abc, ab and ac, giving 6 pairs; ab and abc form 1 more, for 8 in total. Example 3: three distinct indices pair up with each other, for 3 in total.