Polygon Area
Time limit1sMemory limit1024 MB
Given a grid-aligned orthogonally convex polygon as a string of unit moves, compute its area.
- Level
Medium5 of 10
- Topics
- Geometry, Implementation, Prefix sum
- Solved
- No attempts yet
Problem
On squared paper you may draw closed polygons that follow only the grid lines. This means every side of the polygon is horizontal or vertical and has an integer length. The rule for drawing each polygon is given as a string of unit segments: W — left, N — up, E — right, S — down. The polygon never touches or crosses itself; that is, every point along the polygon's path appears exactly once.
The polygon is also orthogonally convex. This means that every horizontal or vertical line that meets the polygon enters it and leaves it exactly once. Put simply, the polygon has no U-shaped parts. For example, NNWSWSEE (left in the figure) gives an orthogonally convex polygon, but SSEEENNWSWNW (right in the figure) does not.

Find the area of the polygon given in this way.
Input
The input consists of exactly two lines. The first line contains the number of segments (). The second line contains a string of length made up only of the characters N, E, S, and W.
Output
Output a single integer: the area of the polygon described in the input.
Hint
