Periodic Sequence
시간 제한1초메모리 제한2048 MB
두 자릿수 수열이 주어질 때, 무한 반복한 수열이 순환 이동으로 같아질 수 있는지 판별한다.
문제
As you may know, some fractions of integers result in an infinite periodic decimal representation. For example, results in , which means that the part is repeating itself. Note that we could also write or . 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 and () --- the length of the first and second sequence.
The second line contains integers () --- the first sequence.
The third line contains integers () --- the second sequence.
출력
Print YES if the two sequences are equal and NO if they are not.