PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000355. Ước số và bội số (Factors and Multiples)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Ước số và bội số (Factors and Multiples)

Factors and Multiples

Source: LightOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given two sets of positive integers AA (with nn elements) and BB (with mm elements), delete some elements from either set so that no remaining pair (a,b)(a,b), with a∈Aa\in A, b∈Bb\in B, satisfies b mod a=0b\bmod a=0.

Find the minimum total number of deleted elements. A value cannot be changed, only deleted.

PHOJ adaptation: One case per file; do not print the original LightOJ Case k: prefix.

Input

  • First line: nn.
  • Second line: nn distinct positive integers in AA.
  • Third line: mm.
  • Fourth line: mm distinct positive integers in BB.

Output

A single integer: the minimum number of deletions.

Subtasks

  • Subtask 1 (20 points): 1<=n,m<=8,1<=Ai,Bj<=10001 <= n,m <= 8, 1 <= A_i,B_j <= 1000.
  • Subtask 2 (30 points): 1<=n,m<=40,1<=Ai,Bj<=1051 <= n,m <= 40, 1 <= A_i,B_j <= 10^5.
  • Subtask 3 (50 points): 1<=n,m<=100,1<=Ai,Bj<=2,147,483,6471 <= n,m <= 100, 1 <= A_i,B_j <= 2,147,483,647.
  • Elements within either set are distinct positive integers.

Examples

Example 1

Input

4
2 3 4 5
4
6 7 8 9

Output

3

Explanation

Delete 2 and 3 from A and 8 from B. Then A={4,5}, B={6,7,9}, with no divisibility edge; fewer than 3 deletions cannot suffice.

Example 2

Input

3
100 200 300
1
150

Output

0

Explanation

150 is not divisible by 100, 200, or 300, hence no deletion is needed.

Example 3

Input

2
2 3
1
6

Output

1

Explanation

Both 2 and 3 divide 6; deleting the sole B element eliminates both edges.