408365: GYM103107 E Elastic Search

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Elastic Searchtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are given $$$n$$$ strings $$$s_1, s_2, \cdots, s_n$$$. We call $$$t$$$ a substring of $$$s$$$ if we can get $$$t$$$ by deleting several consecutive characters (probably zero) from the beginning and/or the end of the string $$$s$$$.

We define a multinest of strings as a sequence $$$p_1, p_2, \cdots, p_m ~ (m \leq n)$$$, where $$$p_i$$$ are pair-wise distinct and $$$s_{p_i}$$$ is a substring of $$$s_{p_{i-1}}$$$ for any $$$2 \leq i \leq m$$$. The length of the multinest is the number of elements in the sequence.

Now you need to calculate the maximum possible length of the multinest among the $$$n$$$ strings.

Input

The first line contains an integer $$$n ~ (1 \leq n \leq 500000)$$$, indicating the number of strings.

Then $$$n$$$ lines follows. Each line contains a string $$$s_i$$$ which consists of only lowercase letters.

It is guaranteed that $$$\sum_{i = 1}^n |s_i| \leq 500000$$$.

Output

Only one integer $$$L$$$ which represents the maximum length of the multinest.

ExampleInput
6
bcba
cba
cbcb
cba
cb
bcb
Output
4
Note

The longest multinest in the sample is $$$(bcba, cba, cba, cb)$$$ of which the the index sequence is $$$(1, 2, 4, 5)$$$ which has length $$$4$$$.

加入题单

上一题 下一题 算法标签: