local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local xs, ys, xt, yt = io.read("*n", "*n", "*n", "*n")
local n = io.read("*n")
local x, y, r = {}, {}, {}
x[1], y[1], r[1] = xs, ys, 0
for i = 1, n do
  x[i + 1], y[i + 1], r[i + 1] = io.read("*n", "*n", "*n")
end
x[n + 2], y[n + 2], r[n + 2] = xt, yt, 0
local n2 = n + 2
local len = {}
len[1] = 0
for i = 2, n2 do
  len[i] = 10000000000
end
local costs = {}
for i = 1, n2 * n2 do
  costs[i] = 10000000000
end

local function getcost(idx1, idx2)
  return mma(0, msq((x[idx1] - x[idx2]) * (x[idx1] - x[idx2]) + (y[idx1] - y[idx2]) * (y[idx1] - y[idx2])) - r[idx1] - r[idx2])
end

for i = 1, n + 1 do
  for j = i + 1, n + 2 do
    local c = getcost(i, j)
    costs[(i - 1) * n2 + j] = c
    costs[(j - 1) * n2 + i] = c
  end
end

local taskstate = {}
for i = 1, n2 do taskstate[i] = false end
local tasks = {}
local tasknum = 0
local done = 0
local tasklim = n2

local function addtask(idx)
  if not taskstate[idx] then
    taskstate[idx] = true
    tasknum = tasknum + 1
    local taskidx = tasknum % tasklim
    if taskidx == 0 then taskidx = tasklim end
    tasks[taskidx] = idx
  end
end
addtask(1)

while done < tasknum do
  done = done + 1
  local taskidx = done % tasklim
  if taskidx == 0 then taskidx = tasklim end
  local src = tasks[taskidx]
  taskstate[src] = false
  for dst = 1, n2 do
    local c = costs[(src - 1) * n2 + dst]
    if len[src] + c < len[dst] then
      len[dst] = len[src] + c
      if dst ~= n2 then addtask(dst) end
    end
  end
end
print(string.format("%.9f", len[n2]))
