P5917 [IOI 1995] Placing Rectangular Blocks

Description

Given $4$ rectangles, find a smallest enclosing rectangle that can contain all $4$ rectangles without overlapping. “Smallest” means the enclosing rectangle has the minimum area. All sides of the $4$ rectangles are parallel to the sides of the enclosing rectangle. There may be multiple different enclosing rectangles with the same minimum area. You should output the side lengths of all such enclosing rectangles.

Input Format

The input has $4$ lines. Each line contains two positive integers representing the two side lengths of one given rectangle. The side length of each rectangle is at least $1$ and at most $50$.

Output Format

The total number of output lines is the number of solutions plus $1$. The first line is an integer representing the minimum area of the enclosing rectangle (Subtask $A$). Each following line represents one solution, given by two numbers $P$ and $Q$, with $P \leq Q$ (Subtask $B$). These lines must be sorted in increasing order of $P$ (smaller $P$ first). All lines must be distinct.

Explanation/Hint

Translated by ChatGPT 5