#include using namespace std; constexpr double INF = 1e9; constexpr double eps = 1e-10; vector dijkstra(const vector>> &graph, int s) { int n = graph.size(); priority_queue, vector>, greater>> hp; vector dist(n, INF); vector used(n, false); dist[s] = 0; hp.emplace(0, s); while (!hp.empty()) { auto [_, u] = hp.top(); hp.pop(); if (used[u]) continue; used[u] = true; for (auto [v, w]: graph[u]) { if (used[v]) continue; if (max(dist[u], w) < dist[v]) { dist[v] = max(dist[u], w); hp.emplace(dist[v], v); } } } return dist; } int main() { int n; cin >> n; vector> planets(n, vector(3)); for (int i = 0; i < n; i++) { cin >> planets[i][0] >> planets[i][1] >> planets[i][2]; } vector>> graph(n); for (int i = 0; i < n; i++) { graph[i].reserve(n); for (int j = 0; j < n; j++) { if (planets[i][2] == planets[j][2]) { graph[i].emplace_back(j, hypot(planets[i][0] - planets[j][0], planets[i][1] - planets[j][1])); } else { graph[i].emplace_back(j, abs(hypot(planets[i][0], planets[i][1]) - hypot(planets[j][0], planets[j][1]))); } } } vector dist = dijkstra(graph, 0); double s = max(.0, dist[n - 1] - eps); long long ans = ceil(s * s); cout << ans << endl; }