Maximize the area of a pen.

Problem statement:

A rectangular animal pen is to be constructed so that one wall is against 
an existing stone wall and the other three sides are to be fence. If N feet
of fence is to be used, determine the dimensions and area of the pen with
maximal area.

The accompanying animation is for N = 500.