A circular rail has circumference L. Gyeonggeun split the rail into L equal parts and numbered the points 0 to L−1 clockwise. He then picked some of those points and placed N ants that run clockwise and M ants that run counterclockwise. No point holds two or more ants.
Every ant on the rail moves a distance of 1 per second. The rail is narrow enough that only one ant fits across it, so when two ants moving in opposite directions meet at a position, both reverse direction at that instant. An ant is a point with no size, so two ants meet only at the moment their positions are exactly equal.
Gyeonggeun tells all the ants apart. Find the smallest number of seconds after which every ant is back at its starting point and moving in its starting direction.
The first line contains the circumference L of the rail, the number N of ants moving clockwise, and the number M of ants moving counterclockwise, separated by spaces.
The second line contains the N points that hold the clockwise ants, separated by spaces.
The third line contains the M points that hold the counterclockwise ants, separated by spaces.
1≤L≤600, 1≤N, 1≤M, and N+M≤600. Every point number is between 0 and L−1, and the N+M given points are all different. The points are not necessarily listed in increasing order.
Print the smallest time in seconds after which every ant is back at its starting point and moving in its starting direction. The answer is always an integer.
In the first example the two ants collide at 0.5 seconds and at 1.5 seconds, and at 2 seconds the state matches the start.