Leave Out All The Rest

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

You are given two integer arrays: an array aa of length nn and an array bb of length mm. All integers in both arrays are pairwise distinct.

An interleaving of the two arrays is an array cc of size n+mn + m such that arrays aa and bb are its disjoint subsequences. Formally, there exist indices i_1<i_2<<i_ni\_1 < i\_2 < \ldots < i\_n such that c_i_1=a_1c\_{i\_1} = a\_1, c_i_2=a_2c\_{i\_2} = a\_2, \ldots, c_i_n=a_nc\_{i\_n} = a\_n, and indices j_1<j_2<<j_mj\_1 < j\_2 < \ldots < j\_m such that c_j_1=b_1c\_{j\_1} = b\_1, c_j_2=b_2c\_{j\_2} = b\_2, \ldots, c_j_m=b_mc\_{j\_m} = b\_m. For these indices, i_xj_yi\_x \neq j\_y for all x=1,2,,nx = 1, 2, \ldots, n and all y=1,2,,my = 1, 2, \ldots, m.

It is clear that there are usually many ways to interleave arrays aa and bb. Find such a way that maximizes the length of the longest increasing subsequence of cc.

입력

The first line of input contains integer nn (1n51051 \le n \le 5 \cdot 10^5) --- the length of array aa.

The second line contains nn integers a_ia\_i (1a_i1091 \le a\_i \le 10^9).

The third line of input contains integer mm (1m51051 \le m \le 5 \cdot 10^5) --- the length of array bb.

The fourth line contains mm integers b_jb\_j (1b_j1091 \le b\_j \le 10^9).

It is guaranteed that the numbers in both arrays are pairwise distinct: a_ia_ja\_i \neq a\_j for iji \neq j, b_ib_jb\_i \neq b\_j for iji \neq j and a_ib_ja\_i \neq b\_j for all valid ii and jj.

출력

Output one integer: the maximum length of the longest increasing subsequence in an interleaving of aa and bb.