title: fitting rectangles in the smallest possible area
body: <blockquote>
    <p>IOI 95</p>
    
    <p><img src="https://i.stack.imgur.com/xWqnp.gif" alt="basic layouts"></p>
    
    <p>The six basic layouts of four rectangles</p>
    
    <p>Four rectangles are given. Find the smallest enclosing (new) rectangle into which these four may be fitted without overlapping. By smallest rectangle, we mean the one with the smallest area.</p>
    
    <p>All four rectangles should have their sides parallel to the corresponding sides of the enclosing rectangle. Figure 1 shows six ways to fit four rectangles together. These six are the only possible basic layouts, since any other layout can be obtained from a basic layout by rotation or reflection. Rectangles may be rotated 90 degrees during packing.</p>
    
    <p>There may exist several different enclosing rectangles fulfilling the requirements, all with the same area. You must produce all such enclosing rectangles.</p>
    
    <p><strong>INPUT FORMAT</strong> <br />
    Four lines, each containing two positive space-separated integers that represent the lengths of a rectangle's two sides. Each side of a rectangle is at least 1 and at most 50.</p>
    
    <p><strong>OUTPUT FORMAT</strong> <br />
    The output file contains one line more than the number of solutions. The first line contains a single integer: the minimum area of the enclosing rectangles. Each of the following lines contains one solution described by two numbers p and q with p&lt;=q. These lines must be sorted in ascending order of p, and must all be different.</p>
  </blockquote>
  
  <p>So this is the problem statement. I figured out that I want to try all 24*16 positions ( you can turn rectangle 90 degrees) against all these basic layouts and check the new area, however I have no idea how to implement this. Anything from some pseudo code to links to articles would help a lot. Thanks in advance.</p>