Consider a path on the plane that starts at the origin and can move only up or right. The path is written as a string of 'U' and 'R' characters. 'U' moves one unit up and 'R' moves one unit to the right. In the figure below, the path given by the string RRRURRUUURRRRRUUR is drawn as a thick line.

Figure 1: a sample 2D path
Now draw the straight line that joins the origin to the last point of the path. It is the dotted line in the figure. Compute the total area that lies between this line and the path, shown in gray in the figure.
When the path crosses the line several times, add up the areas of all the separate regions. If the path consists only of 'R' or only of 'U', the line lies on top of the path and the area is 0.