import sys, math from heapq import heappop, heappush input = sys.stdin.readline 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 """ 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)) def check(mid): stk = [0] visited = [False] * n while(stk): v = stk.pop() if(v == n - 1): return True for nv, nd in route[v]: if(visited[nv] or nd > mid): continue visited[nv] = True stk.append(nv) return False ok = 10 ** 10 ng = -1 while(ok - ng > 1): mid = (ok + ng) >> 1 if(check(mid)): ok = mid else: ng = mid ans = ok print(ans)