#P1278. Word Game Complexity
Word Game Complexity
Word Game Complexity
Io and Ao are playing a word game. They take turns saying a word that consists only of vowels. The rule is that the first letter of the new word must match the last letter of the previous word. The game can start with any word from the given dictionary, and no word may be repeated. The complexity of a game is defined as the total sum of the lengths of the words used in the game, i.e. \(\sum\text{length}(word)\).
Given a dictionary of words (each word only contains vowel letters), determine the maximum complexity that can be achieved following the rules.
Input Format: The first line contains a positive integer n, indicating the number of words in the dictionary. Each of the following n lines contains a word composed solely of vowels.
Output Format: Output a single integer, the maximum possible complexity of the game.
Note: In all formulas, LaTeX format is used. For example, the sum is represented as \(\sum\text{length}(word)\).
inputFormat
The input begins with an integer n (the number of words), followed by n lines each containing a word that only consists of lowercase vowels.
Example:
3 a aa aaa
outputFormat
Output a single integer that represents the maximum achievable complexity of the word game.
Example:
6
sample
3
a
aa
aaa
6
</p>