시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB111100.000%

문제

As editor of a small-town newspaper, you know that a substantial number of your readers enjoy the daily word games that you publish, but that some are getting tired of the conventional crossword puzzles and word jumbles that you have been buying for years. You decide to try your hand at devising a new puzzle of your own.

Given a collection of N words, find an arrangement of the words that divides them among N lines, padding them with leading spaces to maximize the number of non-space characters that are the same as the character immediately above them on the preceding line. Your score for this game is that number.

입력

Input data will consist of one or more test sets.

The first line of each set will be an integer N (1 ≤ N ≤ 10) giving the number of words in the test case. The following N lines will contain the words, one word per line. Each word will be made up of the characters ’a’ to ’z’ and will be between 1 and 10 characters long (inclusive).

End of input will be indicated by a non-positive value for N .

출력

Your program should output a single line containing the maximum possible score for this test case, printed with no leading or trailing spaces.

 

예제 입력 1

5
abc
bcd
cde
aaa
bfcde
0

예제 출력 1

8