class UF: def __init__(self,n): self.p = [-1]*n def f(self,x): if self.p[x]<0: return x else: self.p[x] = self.f(self.p[x]); return self.p[x] def u(self,x,y): x = self.f(x); y = self.f(y) if x==y: return if -self.p[x]<-self.p[y]: x,y = y,x self.p[x] += self.p[y]; self.p[y] = x def s(self,x,y): return self.f(x) == self.f(y) n = int(input()) xyt = [tuple(map(int,input().split())) for _ in range(n)] dij = [] for i,(xi,yi,ti) in enumerate(xyt): for j,(xj,yj,tj) in enumerate(xyt): if i==j: continue if ti==tj: d = (xi-xj)**2+(yi-yj)**2 else: d = (xi**2+yi**2+xj**2+yj**2)-int((4*(xi**2+yi**2)*(xj**2+yj**2))**0.5) dij.append((d,i,j)) uf = UF(n) s = 0 for d,i,j in sorted(dij): if not uf.s(i,j): uf.u(i,j); s = d if uf.s(0,n-1): break print(s)