Let the rectangle be . Name the segments as . Then for P,Q differentiable on a domain containing R,

which becomes

and since dx=0 on these, the last equation is equal to

Proceed similarly for , noticing that dy=0 on the remaining two segments.