WordStack

Time limit1sMemory limit128 MB

Problem

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

You are given $N$ words. Place the words on $N$ lines, one word per line, padding each word with any number of leading spaces to shift it to the right. You may also choose the order in which the words are placed on the lines. You score one point for every non-space character that is equal to the character immediately above it (the character in the same column on the preceding line). Find the maximum score you can achieve.

Input

The input consists of one or more test sets.

The first line of each test set contains an integer $N$ ($1 \le N \le 10$), the number of words. The next $N$ lines each contain one word. Every word is made up only of the lowercase letters a to z and has length between $1$ and $10$, inclusive.

A non-positive value of $N$ ($N \le 0$) marks the end of the input.

Output

For each test set, print the maximum achievable score on its own line, with no leading or trailing spaces.