PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000440. Mạng liên lạc của đàn bò (Moocast)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Mạng liên lạc của đàn bò (Moocast)

Moocast

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

Farmer John has nn cows, numbered from 11 to nn. Cow ii occupies the integer-coordinate point (xi,yi)(x_i,y_i) in the plane. Each cow will receive the same type of radio.

At a nonnegative integer cost XX per radio, its transmission radius is X\sqrt{X}. Cows i,ji,j can communicate directly in either direction precisely when

(xi−xj)2+(yi−yj)2≤X.(x_i-x_j)^2+(y_i-y_j)^2\le X.

A cow receiving a message can relay it to other cows within radio range. Messages may therefore travel through intermediate cows.

Find the least integer cost XX for which a message originating at any cow can eventually reach every other cow.

Input

  • The first line contains an integer nn, the number of cows.
  • The next nn lines each contain two integers xi,yix_i,y_i, the coordinates of cow ii.

Output

Print one nonnegative integer: the minimum cost XX satisfying the requirement.

Subtasks

  • Subtask 1 (20 points): 1≤n≤301\le n\le 30; 0≤xi,yi≤250000\le x_i,y_i\le25000 for all 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤10001\le n\le 1000; 0≤xi,yi≤250000\le x_i,y_i\le25000 for all 1≤i≤n1\le i\le n. yi=y1y_i=y_1 for all 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤10001\le n\le 1000; 0≤xi,yi≤250000\le x_i,y_i\le25000 for all 1≤i≤n1\le i\le n.

Examples

Example 1

Input

4
1 3
5 4
7 2
6 1

Output

17

Explanation

The squared distances of pairs 1,21,2; 2,32,3; and 3,43,4 are 1717, 88, and 22, respectively. At X=17X=17, this chain connects all cows. Cow 11 has squared distances 3737 and 2929 to cows 33 and 44; below 1717 it is isolated. Therefore the minimum is 1717.

Illustration