CF176D Hyper String
Description
Paul Erdős's prediction came true. Finally an alien force landed on the Earth. In contrary to our expectation they didn't asked the humans to compute the value of a Ramsey number (maybe they had solved it themselves). They asked another question which seemed as hard as calculating Ramsey numbers. Aliens threatened that if humans don't solve this problem in less than 2 hours they will destroy the Earth.
Before telling the problem they introduced the concept of Hyper Strings. A Hyper String is made by concatenation of some base strings. Suppose you are given a list of base strings $ b_{1},b_{2},...,b_{n} $ . Now the Hyper String made from indices list $ i_{1},i_{2},...,i_{m} $ is concatenation of base strings $ b_{i1},b_{i2},...,b_{im} $ . A Hyper String can be very large and doing operations on it is very costly for computers.
The aliens asked humans to compute the length of the longest common sub-sequence of a Hyper String $ t $ with a string $ s $ .
Input Format
The first line of input contains the single integer $ n $ ( $ 1
Output Format
Print the length of longest common sub-sequence of Hyper String $ t $ and string $ s $ . If there is no common sub-sequence print 0.
Explanation/Hint
The length of string $ s $ is the number of characters in it. If the length of string $ s $ is marked as $ |s| $ , then string $ s $ can be represented as $ s=s_{1}s_{2}...\ s_{|s|} $ .
A non-empty string $ y=s[p_{1}p_{2}...\ p_{|y|}]=s_{p1}s_{p2}...\ s_{p|y|} $ ( $ 1