import sys, math from heapq import heappop, heappush input = sys.stdin.readline INF = 10 ** 18 def isqrt(n): rn = math.sqrt(n) ok = max(0, int(rn - 2)) ng = int(rn + 2) while(ng - ok > 1): k = (ok + ng) >> 1 if(k * k <= n): ok = k else: ng = k return ok def dijkstra(route): path = [INF] * n que = [(0, 0)] while(que): d, v = heappop(que) if(path[v] <= d): continue path[v] = d if(v == n - 1): break for nv, nd in route[v]: heappush(que, (max(d, nd), nv)) return path[n - 1] """ Main Code """ n = int(input()) planet = [list(map(int, input().split())) for _ in [0] * n] route = [[] for _ in [0] * n] for i in range(0, n-1): for j in range(i+1, n): p1 = planet[i] p2 = planet[j] d = (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2 if(p1[2] != p2[2]): r1 = p1[0] ** 2 + p1[1] ** 2 r2 = p2[0] ** 2 + p2[1] ** 2 d = r1 + r2 - isqrt(4 * r1 * r2) route[i].append((j, d)) route[j].append((i, d)) ans = dijkstra(route) print(ans)