Mix and Build

No attempts yetTime limit1sMemory limit128 MB

Problem

You are given a list of words, where each word is a sequence of lowercase letters. From this list, find the longest chain of words $w_1, w_2, \ldots, w_n$ in which every $w_i$ is a mixed extension of $w_{i-1}$.

A word $A$ is a mixed extension of a word $B$ if $A$ can be obtained by adding exactly one letter to $B$ and then rearranging all of the letters in any order. Equivalently, $A$ is a mixed extension of $B$ when the multiset of letters of $A$ equals the multiset of letters of $B$ together with one extra letter (so the length of $A$ is exactly one greater than the length of $B$).

For example, the words ab, bar, crab, cobra, carbon form a chain of length $5$, because each word is a mixed extension of the one before it.

Input

The input contains at least $2$ and at most $10000$ lines. Each line contains one word. Every word has length at least $1$ and at most $20$ and consists only of lowercase letters. All words are distinct.

Output

Print a single integer: the length of the longest chain (that is, the number of words in it) that can be built from the given words.