Frodo's Gift Wrapping
Time limit1sMemory limit256 MB
Three rotatable rectangles must be packed axis-aligned into one enclosing rectangle of smallest area.
- Level
Medium4 of 10
- Topics
- Brute force, Geometry
- Solved
- No attempts yet
Problem
Frodo bought three birthday presents for Neo. Each present sits in its own rectangular gift box. Frodo wants to put all three gift boxes into a single rectangular wrapping box. A bigger wrapping box costs more, so he wants the one with the smallest area.
The size of the wrapping box depends on how the gift boxes are placed. The placement rules are:
- Every side of a gift box is parallel to a side of the wrapping box.
- Each gift box lies entirely inside the wrapping box, and no two gift boxes overlap.
- A gift box is allowed to touch the border of the wrapping box.
- A gift box can be rotated by 90 degrees.
For example, take gift boxes whose width height is , , and . Placed as in the picture below, they need a wrapping box of size .

Placed as in the next picture, the same three boxes need only a wrapping box of size .

Given the sizes of the three gift boxes, find the smallest area of a wrapping box that safely holds all three.
Input
The first line contains the number of test cases ().
Each test case consists of three lines. Each line contains two integers and (), the width and the height of one gift box, separated by a space.
Output
For each test case, print on its own line the smallest area of a wrapping box that holds all three gift boxes.