World of Cube

Time limit1sMemory limit128 MB

Summary
Given N foci in a box, find the smallest common edge length of axis-aligned cubes centered at the foci whose union covers the whole box.
Level

Medium7 of 10

Topics
Binary search, Geometry, Brute force, Implementation
Solved
No attempts yet

Problem

There is a rectangular box in 3D space, which we call the hall. Inside the hall you are given NN points called foci.

For each focus you place one axis-aligned cube centered at that focus, for a total of NN cubes. All NN cubes must have the same edge length. Cubes may overlap one another, and they may extend outside the hall.

The goal is to cover the entire hall with the union of these NN cubes, leaving no gap.

Given the foci, write a program that finds the smallest edge length of the cubes for which the hall can be completely covered.

Input

The input consists of several test cases.

The first line of each test case contains the number of foci NN and the hall's dimensions XX, YY, ZZ, separated by spaces. (1≤N≤501 \le N \le 50, 1≤X,Y,Z≤1091 \le X, Y, Z \le 10^9) One corner of the hall is the origin (0,0,0)(0, 0, 0) and the opposite corner is (X,Y,Z)(X, Y, Z).

Each of the next NN lines contains the coordinates xx, yy, zz of a focus. (0≤x≤X0 \le x \le X, 0≤y≤Y0 \le y \le Y, 0≤z≤Z0 \le z \le Z)

The last line of the input contains four zeros and must not be processed.

Output

For each test case, print one line in the following format.

k. D

Here kk is the test case number (starting from 1) and DD is the smallest cube edge length that covers the whole hall. DD is always an integer.

Examples3

  1. Example 1

    Input
    2 4 4 8
    2 2 2
    2 2 6
    2 4 4 8
    2 2 2
    2 2 5
    0 0 0 0
    
    Expected output
    1. 4
    2. 6
    
  2. Example 2

    Input
    1 2 2 2
    1 1 1
    0 0 0 0
    
    Expected output
    1. 2
    
  3. Example 3

    Input
    1 2 2 2
    0 0 0
    0 0 0 0
    
    Expected output
    1. 4