BABTWR - Tower of Babylon

Apart from the Hanging Gardens the Babylonians (around 3000-539 b.c.) built the Tower of Babylon as well. The tower was meant to reach the sky, but the project failed because of a confusion of language imposed from much higher above.

For the 2638th anniversary a model of the tower will be rebuilt. n different types of blocks are available. Each one of them may be duplicated as many times as you like. Each type has a height y, a width x and a depth z. The blocks are to be stacked one upon eachother so that the resulting tower is as high as possible. Of course the blocks can be rotated as desired before stacking. However for reasons of stability a block can only be stacked upon another if both of its baselines are shorter.

Input

The number of types of blocks n is located in the first line of each test case. On the subsequent n lines the height yi, the width xi and the depth zi of each type of blocks are given. There are never more than 30 different types available.

There are many test cases, which come one by one. Input terminates with n = 0.

Edited: You can assume that max(xi, yi, zi) <= 2500.

Output

For each test case your program should output one line with the height of the highest possible tower.

Example

Sample input:
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
1
1 1 1
0

Sample output:
342
1

Added by:MichaƂ Czuczman
Date:2004-07-06
Time limit:3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:Swiss Olympiad in Informatics 2004

hide comments
2013-02-09 13:39:00 Harsimran Singh
Yeah ! i have done it man!
2012-02-16 13:20:32 Varshneya
@Lujo:
Because the problem states for one block to be above another, both baselines must be SHORTER.
2011-12-31 23:31:14 Lujo
each block can be duplicated? why the block 1 1 1 can't be (1 1 1)*30? (so the output is 30)
2010-05-14 01:21:22 Lewin Gan
each block can be duplicated as many times as you want, and each can be rotated (so x, y, and z are all interchangeable)
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.