Олимпиадный тренинг

Задача 33313. chain of words


A chain of words of length n is a sequence of words w1, w2, ..., wn such that for 1 ≤ i ≤ n the word wi is a proper prefix of the word wi + 1.
 
Recall that a word u of length k is called a proper prefix of word v of length l if l > k and the first k letters of v match the word u.
 
Set of words S = {s1, s2, ..., sm >}. Find the maximum length of a chain of words that can be constructed using (perhaps not all) the words of this set.
 
Input
The first line of the input file contains the integer m(1 ≤ m ≤ 255). Each of the next m lines contains one word from the set S.
 
All words are not empty, have a length not exceeding 255 characters, and consist only of lowercase Latin letters.
 
Output
Output the answer to the problem in the output file.
 
Input Output
3
a
ab
abc
3
5
a
ab
bc
bcd
add
2