Problem H
Radar

After your boat ran out of fuel in the middle of the ocean, you have been following the currents for 80 days. Today, you finally got your radar equipment working. And it’s receiving signals!
Alas, the signals come from the “radar” station owned by the
eccentric lighthouse keeper Hasse. Hasse’s radar station (which
does not work quite like other radar stations) emits continuous
signals of three different wave-lengths. Therefore, the only
interesting thing you can measure is the phase of a signal as
it reaches you. For example, if the signal you tuned on to has
a wave-length of
So you reach for your last piece of paper to start
calculating – but wait, there’s a catch! On the display you
read: “ACCURACY: 3 METERS”. So, in fact, the information you
get from this signal is that your distance from Hasse’s radar
station is in the union of intervals
What to do? Since the key to surviving at sea is to be optimistic, you are interested in what the smallest possible distance to the lighthouse could be, given the wavelengths, measurements and accuracies corresponding to the three signals.
Task
Given three positive prime numbers
Input
There are three lines of input. The first line is
Output
Print one line with the answer
Sample Input 1 | Sample Output 1 |
---|---|
11 13 17 5 2 4 0 0 0 |
2095 |
Sample Input 2 | Sample Output 2 |
---|---|
941 947 977 142 510 700 100 100 100 |
60266 |