문제
Farmer John has barns (), of which () distinct pairs of barns are connected.
First, Annabelle assigns each barn a distinct integer label in the range , and observes that the barns with labels are connected in a cycle, in that order. That is, barns and are connected for all , and barns and are also connected. All are distinct.
Next, Bessie also assigns each barn a distinct integer label in the range and observes that the barns with labels are connected in a cycle, in that order. All are distinct.
Some (possibly none or all) barns are assigned the same label by Annabelle and Bessie. Compute the maximum possible number of barns that are assigned the same label by Annabelle and Bessie.
입력
The first line contains and .
The next line contains .
The next line contains .
출력
The maximum number of fixed points.
예제 입력 1
6 3
1 2 3
2 3 1
예제 출력 1
6
예제 입력 2
6 3
1 2 3
4 5 6
예제 출력 2
0
예제 입력 3
6 4
1 2 3 4
4 3 2 5
예제 출력 3
4
점수
Inputs 4-5: Inputs 6-8: Inputs 9-15: No additional constraints
코드를 제출하려면 로그인이 필요합니다.
로그인