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

#GL0000212. Ước chung lớn nhất của hai tích khổng lồ (HUGE GCD)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Ước chung lớn nhất của hai tích khổng lồ (HUGE GCD)

Ước chung lớn nhất của hai tích khổng lồ (HUGE GCD)

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Two positive integers A=∏i=1NaiA=\prod_{i=1}^N a_i and B=∏j=1MbjB=\prod_{j=1}^M b_j are supplied as lists of factors because their values may be extremely large. Find G=gcd⁡(A,B)G=\gcd(A,B). Print GG normally if it has at most nine decimal digits. Otherwise print exactly the last nine digits, keeping any leading zeros of this nine-digit suffix.

Input

Line 1: NN. Line 2: NN factors aia_i. Line 3: MM. Line 4: MM factors bjb_j.

Output

Print the result on one line, respecting the nine-digit suffix formatting rule.

Subtasks

  • Subtask 1 (20 points): 1≤N,M≤121\le N,M\le 12; 1≤ai,bj≤100001\le a_i,b_j\le 10000.

  • Subtask 2 (30 points): 1≤N,M≤2001\le N,M\le 200; 1≤ai,bj≤10000001\le a_i,b_j\le 1000000.

  • Subtask 3 (50 points): 1≤N,M≤10001\le N,M\le 1000; 1≤ai,bj≤9999999991\le a_i,b_j\le 999999999.

Examples

Example 1

Input

3
2 3 5
2
4 5

Output

10

Explanation

The products are 30 and 20; their GCD is 10.

Example 2

Input

3
358572 83391967 82
3
50229961 1091444 8863

Output

000012028

Explanation

The GCD has more than nine decimal digits. Its last nine digits are 000012028; leading zeroes must be retained.