SP100 BABTWR - Tower of Babylon

Description

![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP100/7a939db1eae2f77be9ce3ec4d462683703792d71.png)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 Format

The number of types of blocks _n_ is located in the first line of each test case. On the subsequent _n_ lines the height _y $ _{i} $_ , the width _x $ _{i} $_ and the depth _z $ _{i} $_ 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(_x $ _{i} $_ , _y $ _{i} $_ , _z $ _{i} $_ )

Output Format

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