시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB94191230.769%

문제

As you may know, some fractions of integers $\frac{A}{B}$ result in an infinite periodic decimal representation. For example, $\frac{4}{7}$ results in $0.57\overline{142857}$, which means that the $142857$ part is repeating itself. Note that we could also write $0.5714\overline{285714}$ or $0.571\overline{428571428571}$. As you see, it is not trivial to check if two such sequences are equal.

Therefore, you have to help us. You are given only the periodic part of two sequences and need to check if they are equal. Note that the periodic parts are considered equal if they can be made equal by repetition and cyclic shifting.

입력

The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 5 \cdot 10^5$) --- the length of the first and second sequence.

The second line contains $n$ integers $a_i$ ($0 \leq a_i < 10$) --- the first sequence.

The third line contains $m$ integers $b_i$ ($0 \leq b_i < 10$) --- the second sequence.

출력

Print YES if the two sequences are equal and NO if they are not.

예제 입력 1

6 3
1 5 6 1 5 6
6 1 5

예제 출력 1

YES

예제 입력 2

7 3
1 5 6 1 5 6 7
5 6 7

예제 출력 2

NO