Annoying Alliterations
InterviewTime limit2sMemory limit1024 MB
Given n words, find the two words whose combined length is maximized after stripping leading letters from both while their first letters match.
Statement
Bajtazar is a member of the jury for the Find Your Palace Contest, which gives a luxurious palace to the winner. He is now naming his problem. A good problem name consists of exactly two words. Bajtazar finds alliterations annoying, so he removes the first letter from both words until the first letters of the two words differ or one of the words becomes empty. After this operation, the goodness of the name is the sum of the lengths of the two words.
He has a list of words. Find the maximum goodness that can be achieved using words from the list. Bajtazar is busy adding nasty edge cases to the tests, so help him find it.
Input
The first line contains an integer (), the number of words. Each of the next lines contains a word (). Each word consists only of lowercase English letters (a-z). The total number of characters in the words is at most .
Output
Output the maximum goodness that can be achieved.