From the previous question, G-strings are strings that are meant to be made of mostly only the character G. However, G-strings can become contaminated with other capital alphabetical characters, sometimes to the point that there are no more G's left in the G-string. A G-string should not be confused with the article of clothing.
Jeffrey is a collector of G-strings. He has them packaged in a sequence of G-strings, which he refers to as a G-sequence. Jeffrey collects G-strings based on their integrity; if he finds a G-string, he will not add it to his G-sequence if he already has a G-string of the same integrity. As a result, every G-string in his G-sequence has a unique integrity. The ordering of the G-strings within Jeffrey's G-sequence matters, as he has ordered them chronologically by time of entry.
Leo is also a collector of G-strings. Just like Jeffrey, he collects G-strings by integrity and no two G-strings in his G-sequence are of the same integrity. Coincidentally, he also ordered his G-sequence chronologically, like Jeffrey. The two G-string connoisseurs are discussing about their G-sequences, and would like to find the length of the longest subsequence that appears in both G-sequences. A subsequence can be derived from a G-sequence by deleting some of its terms. Help them calculate this number!
On the first line, there will be the integer , the number of G-strings that Jeffrey has in his G-sequence. The next line will contain integers, each denoting the integrity of one of the G-strings in Jeffrey's G-sequence, and in chronological order. If is the integrity of a G-string, .
The next two lines will be of the same form, but will describe Leo's G-sequence instead.
On a single line, print the length of the longest common subsequence of G-strings between Jeffrey's and Leo's G-sequences.
5 1 2 3 4 5 5 2 3 4 5 1