| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 2048 MB | 89 | 19 | 12 | 30.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.
6 3 1 5 6 1 5 6 6 1 5
YES
7 3 1 5 6 1 5 6 7 5 6 7
NO