This page is still under construction.

Parts of this page are still being built. What you see may change.

Polygon Area

Time limit1sMemory limit1024 MB

Summary
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 KK (4≤K≤1064 \le K \le 10^6). The second line contains a string of length KK 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

Examples1

  1. Example 1

    Input
    8
    SSWNWNEE
    
    Expected output
    3