import math import heapq n = int(input()) nodes = [] for _ in range(n): x, y, t = map(int, input().split()) r = math.hypot(x, y) nodes.append((x, y, t, r)) adj = [[] for _ in range(n + 1)] # 1-based indexing for i in range(n): x1, y1, t1, r1 = nodes[i] for j in range(i + 1, n): x2, y2, t2, r2 = nodes[j] if t1 != t2: s_ij = (r1 - r2) ** 2 else: dx = x1 - x2 dy = y1 - y2 s_ij = dx * dx + dy * dy adj[i + 1].append((j + 1, s_ij)) adj[j + 1].append((i + 1, s_ij)) INF = float('inf') dist = [INF] * (n + 1) dist[1] = 0.0 heap = [] heapq.heappush(heap, (0.0, 1)) while heap: current_max, u = heapq.heappop(heap) if u == n: break if current_max > dist[u]: continue for v, s in adj[u]: new_max = max(current_max, s) if new_max < dist[v]: dist[v] = new_max heapq.heappush(heap, (new_max, v)) ans = math.ceil(dist[n]) print(ans)