Joy's Territory

Count the unit squares with all four corners visited by repeating the same N-step walk for K days from each day's endpoint.

Medium7GeometrySimulationMathHash mapNo attempts yetTime limit1sMemory limit256 MB

Problem

You live in a city shaped like a grid of roads. Many roads run very far in the north to south direction, and many other roads run very far in the east to west direction. The gap between two neighbouring north to south roads is 1 km. The gap between two neighbouring east to west roads is also 1 km.

The city has one city hall. The crossing where the city hall stands is written as (0,0)(0, 0). Every crossing of this city is written as crossing (i,j)(i, j) with two integers ii and jj. Crossing (i,j)(i, j) is the crossing reached from crossing (0,0)(0, 0) by going ii km east (i-i km west when i<0i < 0) and jj km north (j-j km south when j<0j < 0).

The city hall keeps one dog named Joy. Joy made a walking plan for KK days. The plan is the following.

  • On the morning of the first of the KK days, Joy is at crossing (0,0)(0, 0). Joy leaves a mark on crossing (0,0)(0, 0). No crossing other than (0,0)(0, 0) has a mark from Joy yet.
  • Joy walks in the daytime on each of the KK days. One day of walking consists of NN steps. In each step Joy moves from the current crossing to a neighbouring crossing and leaves a mark on the crossing it moved to. Joy moves in exactly the same way on every day.
  • After the daytime walk ends, Joy sleeps at the crossing it stands on until the next morning.

The city hall talks about the territory Joy builds over the KK days of walking. If Joy left a mark at least once on all four crossings (a,b)(a, b), (a+1,b)(a+1, b), (a+1,b+1)(a+1, b+1) and (a,b+1)(a, b+1), then the block enclosed by these four crossings belongs to Joy's territory.

The roads of this city are very long, and there are enough roads in both the north to south direction and the east to west direction, so Joy never reaches the end of a road or the end of the city during a walk.

Given Joy's walking plan, write a program that computes the number of blocks that belong to Joy's territory.

Input

The first line contains two integers NN and KK separated by a single space. One day of walking consists of NN steps, and the walking plan lasts KK days.

The second line contains a string SS of length NN. The pp-th character CpC_p (1pN1 \le p \le N) of SS, counted from the left, is one of E, N, W, S. The characters mean the following.

  • If CpC_p is E, the pp-th step moves to the crossing neighbouring on the east.
  • If CpC_p is N, the pp-th step moves to the crossing neighbouring on the north.
  • If CpC_p is W, the pp-th step moves to the crossing neighbouring on the west.
  • If CpC_p is S, the pp-th step moves to the crossing neighbouring on the south.

For crossing (i,j)(i, j), the crossings neighbouring on the east, north, west and south are crossing (i+1,j)(i+1, j), crossing (i,j+1)(i, j+1), crossing (i1,j)(i-1, j) and crossing (i,j1)(i, j-1).

Output

Print the number of blocks that belong to Joy's territory on one line.

Constraints

  • 1N1000001 \le N \le 100000
  • 1K10000000001 \le K \le 1000000000