Processing math: 100%
String combinations - MarisaOJ: Marisa Online Judge

String combinations

Time limit: 1000 ms
Memory limit: 256 MB

Given a string S and n string T1,T2,…,Tm

Find the longest substring of S that can be created using T1,T2,…Tm. One string can be used multiple times.

Input

  • The first line contains an integer n.
  • The second line contains string S.
  • The next n lines, the ith line contains string Ti.

Output

  • Print the length of the longest substring can be formed from T1,T2,…,Tn.

Constraints

  • 1≤n,|S|≤2000.
  • ∑|Ti|≤105.

Example

Input:

3
abbac
ac
b
a

Output:

5