class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x n = int(input()) x = [0] * n y = [0] * n t = [0] * n uf = UnionFind(n) for i in range(n): x[i], y[i], t[i] = map(int,input().split()) a = [] dist = 0 for i in range(n): for j in range(i+1, n): if t[i] == t[j]: dist = (x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2 else: p2 = x[i] ** 2 + y[i] ** 2 q2 = x[j] ** 2 + y[j] ** 2 p2, q2 = min(p2, q2), max(p2, q2) suki = 10 ** 12 kirai = -1 while suki - kirai > 1: targ = (suki + kirai) // 2 tmp = q2 - p2 - targ if tmp <= 0 or tmp * tmp <= 4 * targ * p2: suki = targ else: kirai = targ dist = suki #print(dist) a.append((dist << 30) + (i << 15) + j) a.sort() mask = (1 << 15) - 1 ans = 0 for v in a: dist = v >> 30 i = (v >> 15) & mask j = v & mask ans = dist #print(dist, i, j) uf.union(i, j) if uf.find(0) == uf.find(n-1): break print(ans)