Buggy python submission (verdict: Time Limit Exceeded):
def dist(x1, y1, x2, y2):
    return ((x1 - x2)**2 + (y1 - y2)**2)**0.5


def dist_high(index1, index2):
    return max(dist(
            xyr[index1][0],
            xyr[index1][1],
            xyr[index2][0],
            xyr[index2][1]) - (xyr[index1][2] + xyr[index2][2]), 0)


def min_value_index(array):
    min_value = float("inf")
    min_index = -1
    for v, i in array:
        if min_value > v:
            min_value = v
            min_index = i
    return min_value, min_index

stx, sty, enx, eny = map(int, input().split())
n = int(input())
xyr = [[stx, sty, 0]] + [list(map(int, input().split())) for x in range(n)] + [[enx, eny, 0]]

nodes = [float("inf") for x in range(1002)]
nodes[0] = 0
now = 0
ends = []

while now != (len(xyr) - 1):
    ends.append(now)
    nexts = []
    for i in range(len(xyr)):
        if i == now:
            continue

        nodes[i] = min(nodes[i], nodes[now] + dist_high(now, i))
        nexts.append([nodes[i], i])
    now = min_value_index(filter(lambda x: x[1] not in ends, nexts))[1]
print(nexts[-1][0])


Fixed submission:
def dist(x1, y1, x2, y2):
    return ((x1 - x2)**2 + (y1 - y2)**2)**0.5


def dist_high(index1, index2):
    return max(dist(
            xyr[index1][0],
            xyr[index1][1],
            xyr[index2][0],
            xyr[index2][1]) - (xyr[index1][2] + xyr[index2][2]), 0)


def min_value_index(array):
    min_value = float("inf")
    min_index = -1
    for i, v in array:
        if min_value > v:
            min_value = v
            min_index = i
    return min_value, min_index

stx, sty, enx, eny = map(int, input().split())
n = int(input())
xyr = [[stx, sty, 0]] + [list(map(int, input().split())) for x in range(n)] + [[enx, eny, 0]]

nodes = {x: float("inf") for x in range(len(xyr))}
nodes[0] = 0
now = 0

while now != (len(xyr) - 1):
    for i in nodes.keys():
        if i == now:
            continue

        nodes[i] = min(nodes[i], nodes[now] + dist_high(now, i))
    del nodes[now]
    now = min_value_index(nodes.items())[1]
print(nodes[n + 1])

Buggy python submission (verdict: Runtime Error):
def dist(x1, y1, x2, y2):
    return pow((x1 - x2)**2 + (y1 - y2)**2, 0.5)


def dist_high(i, now):
    if i == -1 and now == -1:
        return dist(stx, sty, enx, eny)
    if now == -1:
        result = dist(stx, sty, xyr[i][0], xyr[i][1])
        result -= xyr[i][2]
    elif i == -1:
        result = dist(xyr[now][0], xyr[now][1], enx, eny)
        result -= xyr[now][2]
    else:
        result = dist(xyr[now][0], xyr[now][1], xyr[i][0], xyr[i][1])
        result -= xyr[i][2] + xyr[now][2]
    return result if result > 0 else 0


debugs = []
def debug(**args):
    debugs.append(args)
    return args["ret"]
def d():
    for i in debugs:
        print(i)


stx, sty, enx, eny = map(int, input().split())
n = int(input())
xyr = [list(map(int, input().split())) for x in range(n)]
xyr = list(sorted(xyr, key=lambda x: dist(stx, sty, x[0], x[1])))

dp = [[False for y in range(1001)] for x in range(1001)]
def calc(i, now):
    if dp[i][now] != False:
        return dp[i][now]

    if i >= n:
        return dist_high(-1, now)
    dp[i][now] = min(
            calc(i + 1, i) + dist_high(i, now),
            calc(i + 1, now)
            )
    return dp[i][now]


print(calc(0, -1))


Fixed submission:
def dist(x1, y1, x2, y2):
    return ((x1 - x2)**2 + (y1 - y2)**2)**0.5


def dist_high(index1, index2):
    return max(dist(
            xyr[index1][0],
            xyr[index1][1],
            xyr[index2][0],
            xyr[index2][1]) - (xyr[index1][2] + xyr[index2][2]), 0)


def min_value_index(array):
    min_value = float("inf")
    min_index = -1
    for i, v in array:
        if min_value > v:
            min_value = v
            min_index = i
    return min_value, min_index

stx, sty, enx, eny = map(int, input().split())
n = int(input())
xyr = [[stx, sty, 0]] + [list(map(int, input().split())) for x in range(n)] + [[enx, eny, 0]]

nodes = {x: float("inf") for x in range(len(xyr))}
nodes[0] = 0
now = 0

while now != (len(xyr) - 1):
    for i in nodes.keys():
        if i == now:
            continue

        nodes[i] = min(nodes[i], nodes[now] + dist_high(now, i))
    del nodes[now]
    now = min_value_index(nodes.items())[1]
print(nodes[n + 1])