Codeforces Round 150 (Div. 1)
C
Colorado Potato Beetle
Codeforces
2200
原题
← BD →
翻译中…

Old MacDonald has a farm and a large potato field, $(10^{10} + 1) × (10^{10} + 1)$ square meters in size. The field is divided into square garden beds, each bed takes up one square meter.

翻译中…

Old McDonald knows that the Colorado potato beetle is about to invade his farm and can destroy the entire harvest. To fight the insects, Old McDonald wants to spray some beds with insecticides.

翻译中…

So Old McDonald went to the field, stood at the center of the central field bed and sprayed this bed with insecticides. Now he's going to make a series of movements and spray a few more beds. During each movement Old McDonald moves left, right, up or down the field some integer number of meters. As Old McDonald moves, he sprays all the beds he steps on. In other words, the beds that have any intersection at all with Old McDonald's trajectory, are sprayed with insecticides.

翻译中…

When Old McDonald finished spraying, he wrote out all his movements on a piece of paper. Now he wants to know how many beds won't be infected after the invasion of the Colorado beetles.

翻译中…

It is known that the invasion of the Colorado beetles goes as follows. First some bed on the field border gets infected. Than any bed that hasn't been infected, hasn't been sprayed with insecticides and has a common side with an infected bed, gets infected as well. Help Old McDonald and determine the number of beds that won't be infected by the Colorado potato beetle.

翻译中…

Input

翻译中…

The first line contains an integer $*n*$ ($1 ≤ *n* ≤ 1000$) — the number of Old McDonald's movements.

翻译中…

Next $*n*$ lines contain the description of Old McDonald's movements. The $*i*$-th of these lines describes the $*i*$-th movement. Each movement is given in the format "$*d*_{*i*}$ $*x*_{*i*}$", where $*d*_{*i*}$ is the character that determines the direction of the movement ("L", "R", "U" or "D" for directions "left", "right", "up" and "down", correspondingly), and $*x*_{*i*}$ ($1 ≤ *x*_{*i*} ≤ 10^{6}$) is an integer that determines the number of meters in the movement.

翻译中…

Output

翻译中…

Print a single integer — the number of beds that won't be infected by the Colorado potato beetle.

翻译中…

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

翻译中…

样例

Input #1
5
R 8
U 9
L 9
D 8
L 2
Output #1
101
InputCopy OutputCopy
Input #2
7
R 10
D 2
L 7
U 9
D 2
R 3
D 10
Output #2
52
InputCopy OutputCopy
题目信息
题号
243C
时间限制
2 s
内存限制
256 MB
标签
DFS 及类似
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。