P2070 [USACO13JAN] Painting the Fence S

Description

Farmer John has devised a brilliant method to paint the long fence next to his barn (think of the fence as a one-dimensional number line). He simply attaches a paint brush to his favorite cow Bessie, and then retires to drink a cold glass of water as Bessie walks back and forth across the fence, applying paint to any segment of the fence that she walks past. Bessie starts at position 0 on the fence and follows a sequence of N moves (1

Input Format

第 $1$ 行:一个整型数 $N$。 第 $2 \sim N+1$ 行:每行描述了 Bessie 的 $N$ 次移动中的一次,例如 `15 L`。

Output Format

$1$ 行:被至少涂了两层涂料的区域总数。

Explanation/Hint

【样例解释】 Bessie 从位置 $0$ 开始,向右移动 $2$ 个单位长度,向左移动 $6$ 个单位长度,向右移动 $1$ 个单位长度,向左移动 $8$ 个单位长度,最后向右移动 $3$ 个单位长度。 $6$ 个单位区域至少被涂了两层涂料,是 $[-11,-8],[-4,-3],[0,2]$ 这些区域。