The Longest Common Subsequence#1618

The Longest Common Subsequence

1 second
128 megabytes
Medium

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 n~(1 \le n \le 1000) — the length of the first sequence. The second line contains integers — the elements of the first sequence, each of which does not exceed 10^4 in absolute value. The third line contains one integer m~(1 \le m \le 1000) — the length of the second sequence. The fourth line contains integers — the elements of the second sequence, each of which does not exceed 10^4 in absolute value.

Output

Print one integer — the length of the longest common subsequence of the two given sequences.

Examples

Example 1

Loading
Loading

Example 3

Loading
Loading