from collections import deque import math INF = 4 * 10 ** 9 n = int(input()) points = [list(map(int, input().split())) for _ in range(n)] dist = [[0 for _ in range(n)] for _ in range(n)] for u in range(n - 1): xu, yu, tu = points[u] for v in range(u + 1, n): xv, yv, tv = points[v] if tu == tv: d = (xv - xu) ** 2 + (yv - yu) ** 2 else: ok = 0 ng = INF target = 4 * (xu ** 2 + yu ** 2) * (xv ** 2 + yv ** 2) while abs(ok - ng) > 1: mid = (ok + ng) // 2 if mid * mid <= target: ok = mid else: ng = mid d = (xu ** 2 + yu ** 2) + (xv ** 2 + yv ** 2) - ok dist[u][v] = d dist[v][u] = d src = 0 dst = n - 1 ng = -1 ok = INF while abs(ok - ng) > 1: mid = (ok + ng) // 2 d = [INF for _ in range(n)] d[src] = 0 dq = deque([src]) while len(dq) > 0: cur = dq.popleft() for nxt in range(n): if d[nxt] < INF or dist[cur][nxt] > mid: continue d[nxt] = d[cur] + 1 dq.append(nxt) if d[dst] < INF: ok = mid else: ng = mid print(ok)