cho.sh
Notes
Loading...

Word Chain

Time limit

2s

Memory limit

128 MB

Problem

Choose words from a dictionary and arrange them in order. The last letter of each word must be the same as the first letter of the next word.

Only words in the dictionary may be used, and the same word cannot be used more than once. Every dictionary word consists only of the uppercase vowels A, E, I, O, and U. The first word may be any word.

The score is the sum of the lengths of the used words. Find the maximum score obtainable by arranging words according to the rule.

Input

The first line contains the number of dictionary words N. (1 ≤ N ≤ 16)

Each of the next N lines contains one dictionary word. Each word consists only of the uppercase letters A, E, I, O, and U, and its length is at most 100. No word is given more than once.

Output

Print one line containing the maximum score obtainable by arranging the words according to the rule.