Under construction

Still being built. Things may change

Lunch Break

Interview

Time limit2sMemory limit1024 MB

Summary
For each restaurant, add the distance from the hideout, the eating time, and the distance to the destination, then output the smallest total.
Level

Easy2 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Super spy Lance Sterling is in the city and is about to leave for a mission. For convenience, a rectangular coordinate system is set up over the city, where the unit segment is one meter long. Lance is currently in a secret hideout at (xs,ys)(x_s, y_s) and needs to reach (xt,yt)(x_t, y_t). He can move in any direction at a speed of 1 meter per second. He is very hungry, though, so he decided to grab a bite before the mission.

The city has nn restaurants where Lance can eat. Restaurant ii is at (xi,yi)(x_i, y_i), and Lance spends exactly tit_i seconds eating there. Find the minimum time needed to reach the destination if he stops at one of the restaurants on the way.

Input

The first line contains four integers xsx_s, ysy_s, xtx_t, and yty_t, the coordinates of the hideout and the destination (∣xs∣,∣ys∣,∣xt∣,∣yt∣≤1 000|x_s|, |y_s|, |x_t|, |y_t| \le 1\,000).

The second line contains one integer nn, the number of restaurants (1≤n≤1 0001 \le n \le 1\,000).

Each of the next nn lines contains three integers xix_i, yiy_i, and tit_i, the coordinates of restaurant ii and the number of seconds spent eating there (∣xi∣,∣yi∣≤1 000|x_i|, |y_i| \le 1\,000, 1≤ti≤1 0001 \le t_i \le 1\,000).

Output

Print one real number, the minimum number of seconds Lance needs to reach the destination after stopping at a restaurant. The answer is accepted if its absolute or relative error does not exceed 10−910^{-9}.

Examples3

  1. Example 1

    Input
    0 0 10 0
    1
    5 0 3
    
    Expected output
    13.000000000000000
    
  2. Example 2

    Input
    0 -5 0 -3
    1
    0 5 10
    
    Expected output
    28.000000000000000
    
  3. Example 3

    Input
    0 0 5 5
    2
    3 3 2
    3 4 1
    
    Expected output
    8.236067977499790