The Tower of Babel
You have an infinite supply of rectangular bricks, each with dimensions x[i]
× y[i]
× z[i]
. These bricks can be oriented in any way, meaning any two dimensions can form the base, while the third dimension becomes the height.
Your task is to develop a program that calculates the maximum possible height of a tower constructed from these bricks. A brick can be stacked on top of another only if the base dimensions of the upper brick are strictly smaller than those of the brick below it.
Input
The first line contains an integer n (1 ≤ n ≤ 30), representing the number of different types of bricks. This is followed by 3n integers, which are n sets of triples x[i]
, y[i]
, z[i]
, specifying the dimensions of each brick type (1 ≤ x[i]
, y[i]
, z[i]
≤ 65000).
Output
Print a single integer, which is the maximum height of the tower that can be built.