public static void Main()
    {
        int minLength = int.MaxValue;
        int maxLength = 0;
        int minWidth = int.MaxValue;
        int maxWidth = 0;

        FileStream inputStream = new FileStream("Tests/test_2d_binpacking.in", FileMode.Open, FileAccess.Read);
        StreamReader sr = new StreamReader(inputStream);
        int n = int.Parse(sr.ReadLine());
        Tuple<int, int>[] files = new Tuple<int, int>[n];
        //create a tuple of length&width representing all files.
        for (int i = 0; i < n; i++)
        {
            string[] inputs = sr.ReadLine().Split(' ');
            int templength = int.Parse(inputs[0]);
            int tempwidth = int.Parse(inputs[1]);
            int length = Math.Max(templength, tempwidth);
            int width = Math.Min(templength, tempwidth);
            files[i] = new Tuple<int, int>(length, width);
            maxLength += length;
            maxWidth += width;
            minLength = Math.Min(minLength, length);
            minWidth = Math.Min(minWidth, width);
        }

        int dropBoxLength = minLength;
        int dropBoxWidth = maxWidth;
        int bestArea = maxWidth * maxLength;
        int bestWidth = maxWidth;
        int bestLength = maxLength;
        string treeDump = string.Empty;
        //heuristics as described in summary at top
        while (dropBoxLength <= maxLength && dropBoxWidth >= minWidth)
        {
            if (dropBoxLength * dropBoxWidth < bestArea)
            {
                DropBox dp = new DropBox(files, dropBoxLength, dropBoxWidth);
                if (dp.IsStable)
                {
                    bestArea = dropBoxLength * dropBoxWidth;
                    bestWidth = dropBoxWidth;
                    bestLength = dropBoxLength;
                    dropBoxWidth--;
                    treeDump = dp.Dump();
                    continue;
                }
                else
                {
                    dropBoxLength++;
                    continue;
                }
            }
            dropBoxWidth--;
        }
        //Console.WriteLine ("({1},{2}),{0}", bestArea, bestLength, bestWidth);
        Console.WriteLine("{0}", bestArea);
        Console.Error.WriteLine(treeDump);
    }