Cranes

Interview

Time limit1sMemory limit128 MB

Summary
Choose a subset of at most 15 crane locations, each with a radius, so that every pair's distance exceeds the sum of radii, maximizing the total squared radius.
Level

Medium6 of 10

Topics
Brute force, Geometry, Backtracking, Implementation
Solved
No attempts yet

Problem

A crane is a great tool for putting up a building, and using several cranes makes construction go even faster. But when too many cranes work on the same building they can become dangerous: as a crane spins around it can bump into another crane and topple over, causing serious damage. Safety rules therefore require the cranes to be spaced far enough apart that no part of one crane can ever touch any part of another crane.

The construction site is a square grid, and several grid points are marked as possible crane locations. A crane placed at a location has an arm of length rr that rotates around that location, so it covers every point within distance rr of the location (a disk of radius rr). Two placed cranes are allowed together only if their disks never touch, that is, the distance between their locations is strictly greater than the sum of their arm lengths.

Respecting the safety rule, choose which of the marked locations to place cranes on so that the total area covered by all the placed cranes is as large as possible.

Input

The first line contains an integer TT, the number of test cases. Each test case starts with a line containing an integer CC, the number of possible crane locations, with C≤15C \le 15. Each of the next CC lines contains three integers xx, yy, and rr, each between −10000-10000 and 1000010000 inclusive: (x,y)(x, y) are the grid coordinates of the location and rr is the arm length of the crane that can be placed there.

Output

For each test case, let AA be the maximum total area that can be covered while respecting the safety rule. Output one line with the integer BB such that A=B×πA = B \times \pi. Because a crane covers an area of πr2\pi r^2 and the placed disks never overlap, BB equals the largest possible sum of r2r^2 over a set of cranes chosen so that none of them touch.

Examples1

  1. Example 1

    Input
    1
    3
    0 0 4
    5 0 4
    -5 0 4
    
    
    Expected output
    32