VisaOA #8
Library Prefix Pairs
Estimated MediumJudge-ready
Topics (AI-labelled)Trie & CodecHashing
Count ordered index pairs i≠j such that title i is a prefix of title j; different indices with identical titles also count.
Input
n (1≤n≤200000), followed by n lines of non-empty lowercase strings, each of length ≤1000, with total length ≤200000; the ranges are site-added to bound Trie memory.
Output
Output the number of ordered pairs.
Example 1
Input:
3
ab
abc
ab
Output:
4
Example 2
Input:
1
a
Output:
0
Example 3
Input:
4
car
cart
cat
car
Output:
4
Editorial
Loading solution…