Capital OneOA #9
Book Title Catalog — Count Titles That Are Prefix of Another
估计中等可在线判题
Given a list of book titles titles, count the ordered index pairs (i,j) such that i≠j and titles[i] is a prefix of titles[j]. Identical titles at different indices also count as prefixes.
输入格式
The first line contains n (1≤n≤200000), followed by n lines, each a non-empty title consisting only of lowercase English letters, with length 1..1000; the total length of all titles is ≤2×10^6. The character set and constraints are site supplements.
输出格式
Output the number of ordered index pairs that satisfy the condition.
样例 1
输入:
6
wall
wallpaper
science
wallet
philosophy
phil
输出:
3
样例 2
输入:
1
a
输出:
0
样例 3
输入:
4
ab
ab
abc
b
输出:
4