Mirko has received a homework assignment to compute the greatest common divisor of the two positive integers and . Since the numbers are quite large, the teacher provided him with smaller integers whose product is , and integers with product .
Mirko would like to verify his result, so he has asked you to write a program to solve his problem.
If the result is more than 9 digits long, output only the last 9 digits.
Input Specification
The first line of input contains the positive integer .
The second line of input contains space-separated positive integers less than , whose product is the number .
The third line of input contains the positive integer .
The fourth line of input contains space-separated positive integers less than , whose product is the number .
Output Specification
The first and only line of output must contain the greatest common divisor of numbers and . If the result is more than digits long, output only the last (least significant) digits.
Sample Input 1
3
2 3 5
2
4 5
Sample Output 1
10
Explanation for Sample Output 1
The greatest common divisor of numbers and equals .
Sample Input 2
4
6 2 3 4
1
1
Sample Output 2
1
Sample Input 3
3
358572 83391967 82
3
50229961 1091444 8863
Sample Output 3
000012028
Comments