The Elric brothers, Edward and Alphonse, have suspicions of sinister, illegal experiments occurring in the "abandoned" 5th Laboratory given by coordinates ,
, and
.
Driven by their pursuit of the truth, the boys construct a risky plot: while their allies distract the guards, they will stealthily infiltrate the lab from a hiding spot.
To ensure their success, they turn to you, an expert state programmer working alongside alchemists. Your task is to compute the minimum time it would take them to reach the lab.
There are hiding spots nearby with coordinates of hiding spot
represented by
,
, and
.
When on equal elevation as the lab, the boys can run at a speed of units/second. If their elevation
is lower than the lab, they must climb vertically upward at a speed of
unit/second. If their elevation is above the lab, they must glide using forwards and downward velocities of exactly
and
units/second respectively.
The boys can only glide, as free falling is not stylish. However, they do not necessarily need to glide straight.
In addition, the boys can only carry either gliders or climbing gear, but not both, as carrying both would be too heavy (Edward is too weak).
Constraints
Input Specification
The first line contains three integers, ,
, and
representing the coordinates of the lab.
The second line contains a positive integer , representing the number of hiding spots.
The next lines each contain three integers
,
, and
, representing the coordinates of hiding spot
.
Output Specification
Output a single line containing a single number: the minimum time needed to reach the lab.
Note: Outputs within relative error of the official solution will be accepted.
Sample Input 1
1 1 1
2
5 4 1
1 2 -5
Sample Output 1
2.5
Explanation for Sample 1
The first hiding spot, the brothers run or
meters at a speed of
units/second taking
seconds.
The second hiding spot, the brothers climb for meters at
unit/second and run
meter at
units/second taking
seconds in total.
The faster of the two being seconds.
Sample Input 2
1 1 1
2
1 2 1
1 1 1
Sample Output 2
0
Explanation for Sample 2
The optimal hiding spot is already in the lab.
Sample Input 3
0 0 0
2
0 7 4
0 3 8
Sample Output 3
2
Explanation for Sample 3
The first and second hiding spots take and
seconds respectively.
Comments