The Longest Common Subsequence
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Two sequences are given. Find the length of their longest common subsequence.
A subsequence is a sequence that can be derived from the original sequence by deleting some elements without changing the order of the remaining elements.
Input
The first line contains one integer — the length of the first sequence.
The second line contains integers — the elements of the first sequence, each of which does not exceed in absolute value.
The third line contains one integer — the length of the second sequence.
The fourth line contains integers — the elements of the second sequence, each of which does not exceed in absolute value.
Output
Print one integer — the length of the longest common subsequence of the two given sequences.
Examples
Input #1
Answer #1
Input #3
Answer #3
Submissions 5K
Acceptance rate 44%