#P7861. Loda Mind Transmission
Loda Mind Transmission
Loda Mind Transmission
A secret planet S4 is inhabited by a peculiar creature called Loda. Each Loda is composed of N strings: x1, x2, ..., xN. Research has shown that the number of mind transmissions a Loda can perform is equal to the length of the longest subsequence of its strings satisfying the following condition:
For any two strings xi and xj (i < j) in the subsequence, it must hold that xj starts with and ends with xi. In mathematical notation, using LaTeX, for a valid adjacent pair in the subsequence, we require:
$$\text{prefix}(x_j, |x_i|)=x_i \quad\text{and}\quad \text{suffix}(x_j, |x_i|)=x_i $$Your task is to determine the maximum mind transmissions a Loda can perform, i.e. compute the length of the longest valid subsequence of strings.
inputFormat
The input consists of multiple lines. The first line contains an integer N denoting the number of strings. The following N lines each contain one non-empty string xi.
You can assume that all strings consist of standard ASCII characters.
outputFormat
Output a single integer representing the length of the longest valid subsequence where for any two strings xi and xj in the subsequence with i < j, xj has xi as both its prefix and suffix.
sample
3
a
aba
ababa
3
</p>