The cows want to build a tower out of the blocks they found. They want you to tell them how high the tower will be, given the sizes of the blocks. Each block has a width and length in addition to being one unit in height. The blocks must be stacked with all their edges parallel to a set of axes, and the blocks can be rotated 90 degrees, if you wish. In order to build a stable tower, each higher block must be no larger than the block on which it sits -- both the width and the length of each higher block must be no larger than the width and length of the block upon which it sits.
Your job is to determine the height of the tallest possible stable tower that can be built with a given collection of blocks.
A single line with an integer telling how high the tallest possible stable tower can be.