WORDS | 프로그래밍의 벗 PivotOJ
PivotOJ

WORDS

시간 제한: 2000ms메모리 제한: 128MB출처: CHC 2001 Croatian Olympiad in InformaticsBOJ 2320

문제

Io and Ao are playing a word game. They alternately say words consisting of vowels only so that the first letter of every new word is the same as the last letter of the previous word. A game can start with any word.

It is forbidden to say any word twice. Only words from given dictionary can be used in a game.

A complexity of a game is defined as a sum of lengths of all the spoken words during the game.

Write a program that will determine the maximal possible complexity of a game that can be played using words from a given dictionary.

입력

The first line of input file contains a natural number N, 1 ≤ N ≤ 16, the numbers of words in a dictionary. Each of next N lines contains one word from a dictionary. A word is a sequence of characters ‘A’, ‘E’, ‘I’, ‘O’ and ‘U’. Length of every word will be 100 or less. All the words will be different.

출력

The first and only line of output file should contain the maximal possible complexity of the game.

예제

예제 1

입력
3
AEIOU
UIU
EO
출력
8

예제 2

입력
4
AEEEO
OEOAEEE
AO
O
출력
13

예제 3

입력
5
IOO
IUUO
AI
OIOOI
AOOI
출력
16
코드를 제출하려면 로그인하세요.