Greatest Common Divisor

Time limit1sMemory limit192 MB

Problem

There are two positive integers A and B. A is the product of N given positive integers, and B is the product of M given positive integers. These products may be very large.

Given both lists of factors, compute the greatest common divisor of A and B.

Input

The first line contains N (1 <= N <= 1000). The second line contains N positive integers separated by spaces. Each integer is less than 1,000,000,000, and their product is A.

The third line contains M (1 <= M <= 1000). The fourth line contains M positive integers separated by spaces. Each integer is less than 1,000,000,000, and their product is B.

Output

Print the greatest common divisor of A and B. If its decimal representation has more than 9 digits, print only the last 9 digits. If those final 9 digits start with zeroes, print those zeroes too.