from math import sqrt from collections import deque n=int(input()) Z=[list(map(int,input().split())) for _ in range(n)] G=[[0 for _ in range(n)] for _ in range(n)] dist=[0] dist_set=set([0]) def max_sqrt(a): l=1 r=int(sqrt(a)+1) while(r-l>1): mid=(r+l)//2 if(mid**2<=a): l=mid else: r=mid return l for i in range(n-1): for j in range(i+1,n): if i==j: continue if Z[i][2]==Z[j][2]: d=(Z[i][0]-Z[j][0])**2+(Z[i][1]-Z[j][1])**2 else: d1=Z[i][0]**2+Z[i][1]**2 d2=Z[j][0]**2+Z[j][1]**2 d=d1+d2-max_sqrt(4*d1*d2) G[i][j]=d G[j][i]=d if d not in dist_set: dist.append(d) dist_set.add(d) def dfs(G,d): not_visit=set([i for i in range(1,n)]) Q=deque() Q.append(0) while(Q): v=Q.pop() visit=set() for i in not_visit: if G[v][i]<=d: visit.add(i) Q.append(i) if i==n-1: return True not_visit-=visit return False dist.sort() l=-1 r=len(dist)-1 while(r-l>1): mid=(r+l)//2 if(dfs(G,dist[mid])): r=mid else: l=mid print(dist[r])