import sys input = sys.stdin.readline N=int(input()) P=[list(map(int,input().split())) for i in range(N)] OK=3200000000 NG=-1 while OK>NG+1: mid=(OK+NG)//2 CAN=[0]*N CAN[0]=1 Q=[0] while Q: x=Q.pop() x0,y0,t0=P[x] for i in range(N): if CAN[i]==1: continue x1,y1,t1=P[i] if t0==t1: dis=(x0-x1)**2+(y0-y1)**2 if dis<=mid: CAN[i]=1 Q.append(i) else: a=(x1*x1+y1*y1) b=(x0*x0+y0*y0) if (a+b-mid)**2<=4*a*b: CAN[i]=1 Q.append(i) if CAN[N-1]==1: OK=mid else: NG=mid print(OK)