Count distinct grid cells visited when walking L steps from the origin following N, S, E, and W commands.
Easy3SimulationHash mapInterviewNo attempts yetTime limit2sMemory limit256 MBJuhyun and Jaeyun play a direction calling game. Jaeyun stands at the origin of the two dimensional plane, and whenever Juhyun calls out one of the four compass directions, Jaeyun moves one cell that way. If Juhyun calls out south, south, west, north, then Jaeyun moves one cell south, one more cell south, one cell west, and finally one cell north.
Jaeyun leaves a footprint on every cell he steps on, always with his toes pointing exactly north. Stepping again on a cell that already carries a footprint puts his foot exactly on top of it, so the number of footprints does not grow. The origin, where he starts, already carries one footprint.
After calling out every command, Juhyun wants to count the footprints left on the plane to check that Jaeyun followed the commands, but there are far too many to count by eye. Read the command string and compute how many footprints are left on the plane.

For the commands SENWWSEN, Jaeyun moves along (0, 0) → (0, -1) → (1, -1) → (1, 0) → (0, 0) → (-1, 0) → (-1, -1) → (0, -1) → (0, 0). He stands on a cell nine times counting the origin, but some coordinates repeat, so only 6 footprints are left on the plane.
The first line contains the length L (1≤L≤1000) of the commands Juhyun called out. The second line contains the command string of length L. The string consists only of the uppercase letters E, W, S, N and contains no spaces. E means east, W means west, S means south, and N means north.
Print the number of footprints left on the plane.