DERP - Derp

no tags 

Usually, producing methamphetamine is somewhat laborous and boring. There are some TV series who assume that there is a new way to produce it, being way cheaper than actually is. Nonsense. The fact is there is a new drug around, called Krokodil. This drug is a variation of morphine, which gives 8 to 10 times more hallucination than “meth”, costing up to 10 times less than it.

Your friend Derp works in a “meth lab” and, while he was doing some tests, looking at the microscope, he found an interesting property: if he isolates the most far away pair of atoms in it, he will produce a substance as powerful (perhaps even more) as Krokodil is. This happens because one of the electron moves from one atom to the other.

But, most of the times, there are hundreds, maybe thousands of particles in each sample, each of them using several layers, making kinda hard to find out which is the longest distance. There’s an unusual fact about this distance calculus:

Each electron from these particles are kinda dumb; they are only able to move in horizontal and vertical axis. Also, since there are nanometrical layers, and distance is also considered for calculation between layers (which is the same), and a electron, in the layer L, with position (x, y), can only move to layers L + 1 and L − 1, if any of those exist, in the same relative position as in layer L.

Input

Each input contains several test cases. The first line of every test case contains a number N, which is the number of particles of that sample (2 ≤ N ≤ 100,000).

Then there are N lines, each of which contains 3 integers, li, xi, yi, which are the actual layer, the position corresponding corresponding to the X-axis, and the position corresponding to Y-axis (1 ≤ li, xi, yi ≤ 1,000,000,000).

Output

For each output you print one integer, DISTANCE, which corresponds to the value of the farthest distance between particles in the that sample.

Example

Input:
5
1 1 2
3 4 1
2 5 7
4 1 1
3 3 3
0

Output:
12

hide comments
[Rampage] Blue.Mary: 2013-03-28 09:25:44

The problem requires calculating the farthest distance pair under 3D Manhattan distance.

Renato Parente: 2012-02-12 13:32:26

The final test case end with N = 0

The correct input is

5
1 1 2
3 4 1
2 5 7
4 1 1
3 3 3
0


Added by:Paulo Costa
Date:2012-02-01
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:PUCP