Welcome to ZOJ
 Contests Information Problems Runs Statistics Ranklist Clarification
62 - ZOJ Monthly, January 2008 - 1003
Common Factor

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Given two polynomials with integer coefficients, check if they have a common factor. A common factor is a polynomial with degree larger than 0 that will divide evenly into both polynomials.

Input

There are many test cases. Every test case begins with a line containing two integers n and m, 0<= n, m <= 100. The second line contains n+1 integers An(An != 0), An-1, An-2, ... A1, A0. Ai is the coefficient of the term with degree i in the first polynomial. The third line contains m+1 integers Bm(Bm != 0), Bm-1, Bm-2, ... B1, B0. Bi is the coefficient of the term with degree i in the second polynomial. All coefficients are between -4000 and 4000 inclusive.

Output

For each test case, print "YES" if the two polynomials have a common factor in a line, or print "NO" instead if the two polynomials have no common factor.

Sample Input

2 2
1 0 -4
1 2 -3
2 1
1 3 2
1 2

Sample Output

NO
YES

Author: HE, Rongqiang

Submit    Status