#ARC064C. [ARC064E] Cosmic Rays

[ARC064E] Cosmic Rays

Score : 600600 points

Problem Statement

On the xxyy-plane, Snuke is going to travel from the point (xs,ys)(x_s, y_s) to the point (xt,yt)(x_t, y_t). He can move in arbitrary directions with speed 11. Here, we will consider him as a point without size.

There are NN circular barriers deployed on the plane. The center and the radius of the ii-th barrier are (xi,yi)(x_i, y_i) and rir_i, respectively. The barriers may overlap or contain each other.

A point on the plane is exposed to cosmic rays if the point is not within any of the barriers.

Snuke wants to avoid exposure to cosmic rays as much as possible during the travel. Find the minimum possible duration of time he is exposed to cosmic rays during the travel.

Constraints

  • All input values are integers.
  • 109xs,ys,xt,yt109-10^9 \leq x_s, y_s, x_t, y_t \leq 10^9
  • (xs,ys)(x_s, y_s)(xt,yt)(x_t, y_t)
  • 1N1,0001 \leq N \leq 1,000
  • 109xi,yi109-10^9 \leq x_i, y_i \leq 10^9
  • 1ri1091 \leq r_i \leq 10^9

Input

The input is given from Standard Input in the following format:

xsx_s ysy_s xtx_t yty_t

NN

x1x_1 y1y_1 r1r_1

x2x_2 y2y_2 r2r_2

::

xNx_N yNy_N rNr_N

Output

Print the minimum possible duration of time Snuke is exposed to cosmic rays during the travel. The output is considered correct if the absolute or relative error is at most 10910^{-9}.

-2 -2 2 2
1
0 0 1
3.6568542495

An optimal route is as follows:

e9c630751968b7051df5750b7ddc0e07.png

-2 0 2 0
2
-1 0 2
1 0 2
0.0000000000

An optimal route is as follows:

fb82f6f4df5b22cffb868ce6333277aa.png

4 -2 -2 4
3
0 0 2
4 0 1
0 4 1
4.0000000000

An optimal route is as follows:

d09006720c225cbe69eae3fd9c186e67.png