시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB259180459630.533%

문제

창영이는 방 청소를 하다가 자와 각도기를 발견했다. 다음날 창영이는 학교에 자와 각도기를 들고 갔고, 현우와 "작도 대결"을 하려고 한다.

창영이는 각도기와 자를 이용해서 만들 수 있는 각을 알고 있고, 두 각을 합하거나 빼서 새로운 각을 만드는 방법을 알고 있다. 현우가 어떤 각도를 외치면, 창영이는 자와 각도기를 이용해서 현우가 외친 각도를 작도해야 한다. 작도할 때는 새로운 각을 이용해서 또다른 새로운 각을 만드는 것도 가능하다.

현우가 외치는 각도를 창영이가 만들 수 있는지 없는지 구하는 프로그램을 작성하시오.

입력

첫째 줄에 창영이가 만드는 방법을 알고 있는 각의 수 N과 현우가 외친 각의 개수 K가 주어진다. (1 ≤ N, K ≤ 10)

둘째 줄에는 창영이가 만들 수 있는 각이 주어진다. 모든 각도는 360보다 작다.

셋째 줄에는 현우가 외친 각이 주어진다. 이 각도 360보다 작다.

출력

현우가 외친 각도를 창영이가 만들 수 있다면 YES를, 없다면 NO를 입력으로 주어진 순서대로 한 줄에 하나씩 출력한다.

예제 입력 1

2 1
30 70
40

예제 출력 1

YES

70°를 만들고, 30°를 빼서 40°를 만들면 된다.

예제 입력 2

1 1
100
60

예제 출력 2

YES

100°를 15번 더하면 1500°가 된다. 1500°는 60°와 같다.

예제 입력 3

3 2
10 20 30
5 70

예제 출력 3

NO
YES
W3sicHJvYmxlbV9pZCI6IjI5MTYiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWM3OTBcdWM2NDAgXHVhYzAxXHViM2M0XHVhZTMwIiwiZGVzY3JpcHRpb24iOiI8cD5cdWNjM2RcdWM2MDFcdWM3NzRcdWIyOTQgXHViYzI5IFx1Y2NhZFx1YzE4Y1x1Yjk3YyBcdWQ1NThcdWIyZTRcdWFjMDAgXHVjNzkwXHVjNjQwIFx1YWMwMVx1YjNjNFx1YWUzMFx1Yjk3YyBcdWJjMWNcdWFjYWNc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