The Planimeter Problem

Given a line segment drawn from 5 to 7 along a reference line marked in units from an arbitrary origin, it is obvious that the line segment is 2 units long. In fact, however, we obtain this answer by taking the imaginary 7 unit long line and subtracting an imaginary 5 unit long line: 7-5 is 2. A planimeter is a mechanical device that employs the two-dimensional equivalent of this geometric trick to determine the area enclosed by merely tracing the perimeter. In this problem a planimeter works only with right angles.

For example, consider the following walk:

Move			Command
Right 3			r 3
Up 1			u 1
Left 1			l 1
Up 2			u 2
Left 3			l 3
Down 2			d 2
Right 1			r 1
Down 1 (closed)		d 1
Down 1			d 1
Left 1			l 1
Up 1			u 1
Right 1 (closed)	r 1
This traces two enclosed areas: 9 units and 1 unit.

You are to write a program that accepts a list of motion commands tracing a series of perimeters, computes and prints the area enclosed by each, and prints the total area enclosed by all perimeters.

Each motion command is on a line by itself in the form given above: a single character in the first column indicating the direction (u,d,l,r), followed by a space and then an integer which indicates a distance to move in that direction.

There is no command separating the moves tracing one perimeter from those tracing the next, but each perimeter is a closed walk -- each starting and ending at the same point. This fact should be used to distinguish one perimeter from the next. Print each enclosed area as an integer, At end of file, print the total area accumulated from all walks of perimeters.

For the example given above, your program should output:

   9
   1
====
  10
Notes:
  1. The maximum displacement from the point of origin may be large, but will not exceed the range of an integer variable.
  2. A planimeter can actually measure areas of arbitrary shape (such as animal skins) and it does this using Greene's Theorem and some integral calculus, but that's not important for this question.

Submit

submit149 perimeter ...