There is a long
straight avenue with k traffic lights in the city of NN. All the
traffic lights in this avenue are identical, and they have only two states: red
(stop) and green (drive). The states change each n seconds for
each working traffic light. This interval is the same for all lights. However,
the lights may have been initially powered on at different times. The switching
times of traffic light number i are determined by the time ri
when it was powered on. After the traffic light is powered on it will remain
green for n seconds. Then, at ri
+ n, it will turn red, and n more seconds later (at
ri + 2n) it will turn green
again, and so on.
There are m
cars at the beginning of the avenue. At point in time t0
= 0 seconds all the cars start moving along the avenue in the same direction
with different but constant speeds s1, s2,
…sm m/sec. The traffic lights are installed at
positions d1, d2, …, dk
meters from the beginning of the avenue. A car may pass the traffic light i
only if at point in time t, when the car reaches position di,
traffic light number i is in green state and it is not
changing state at the moment t.
ri + 2xn < t < ri
+ (2x+1)n for some non-negative number x.
Write a program
that will accept parameters n, m, k,
speeds s1, …, sm and
distances d1, d2, …, dk,
and calculate the times r1, r2,
…, rk to power on the lights in such a way that
all m cars will drive along the avenue without stopping. Note
that the traffic lights are designed so that the moments of powering on r1,
r2, …, rk have to be expressed
as an integer number of seconds. If several solutions exist then any of them
will be considered correct.
Limitations
All input and
output numbers are integer.
1 <= n <=
106, 1 <= m, k <= 1000;
1 <= si, di <= 106; i
¹ j : si ¹ sj, di ¹ dj.
0 <= ri <= 109.
Input
The first line
of the input file contains 3 integers n, m, k
separated by spaces. The second line consists of m pairwise
different integer numbers s1, s2,
…sm separated by spaces. These numbers define
the speeds of the cars in m/sec. The third line contains k
pairwise different integer numbers d1, d2,
…, dk separated by spaces. These numbers define
the positions of traffic lights (distance from the the beginning of the avenue
in m.).
Output
The first line
of the input file contains 0 if there is no integer solution, or number k
if such a solution exists. If there is a solution, then the following
line contains k integers r1, r2,
…, rk delimited by exactly one space.
Samples
Standard input
|
Standard output
|
2 2 1
20 11
100
|
1
4
|
20 10
100
|
0
|