Highways and Counties

Find the smallest road length limit so cities joined by shorter roads form a group whose populations hold a subset summing to a multiple of K.

Hard9Minimum spanning treeDynamic programmingUnion-findGeometryNo attempts yetTime limit2sMemory limit64 MB

Problem

A faraway country has NN cities. An election just ended and a new prime minister took office. The country has no roads at all yet, so the prime minister decided to modernize it by connecting some cities with two way highways and forming counties. Two cities belong to the same county if you can travel from one to the other along the new roads. Every city belongs to exactly one county, and every county holds at least one city.

The cities are points in a two dimensional coordinate system. A road between two cities is the line segment that joins the two points, and the length of the road is the length of that segment. Lengths are measured in kilometers.

The country is in a recession and the budget is small, so the prime minister will not build a road longer than DD kilometers. The prime minister is pleased by small things: he is happy if some county holds a nonempty subset of its cities whose numbers of residents sum to a multiple of KK. That subset may be all the cities of the county. For example, if K=4K = 4 and a county holds cities with 3, 5 and 7 residents, the prime minister is happy, because the first two cities hold 8 residents together.

Find the smallest DD for which the prime minister can build the roads and be happy.

Input

The first line contains the integers NN and KK (1N500001 \le N \le 50000, 1K301 \le K \le 30).

Each of the next NN lines contains the integers xix_i, yiy_i, kik_i (0xi,yi,ki1000000000 \le x_i, y_i, k_i \le 100000000): the xx coordinate of a city, the yy coordinate of that city, and the number of residents in it. No two cities share the same coordinates. No city has a number of residents divisible by KK.

Output

Print on a single line the smallest DD for which the prime minister can build the roads and be happy, rounded to three decimal places. The input is always such that an answer exists.

Hint

In the first example the prime minister is happy only when every city lies in one county, and the smallest DD that allows it is 1.414.

In the second example the prime minister is happy once the first five cities lie in one county. With D=5.657D = 5.657 he can connect cities 1, 2, 3 and 5 to city 4. Cities 1 through 5 then hold 11 residents in total, which is divisible by 11.