11416: AOI2021 - Robot Vacuum
[Creator : ]
Description
Irene has a robot vacuum cleaner that automatically cleans her floor. Each day, the robot performs
the same sequence of $K$ instructions.
There are four possible instructions, each represented by an uppercase character. Each instruc tion moves the robot one step in one of the four cardinal directions:
Irene has asked for your programming help. What is the smallest number of instructions needed to add to the end of the sequence so that the robot finishes where it started?
There are four possible instructions, each represented by an uppercase character. Each instruc tion moves the robot one step in one of the four cardinal directions:
-
N
- the robot moves one step north (↑). -
E
- the robot moves one step east (→). -
S
- the robot moves one step south (↓). -
W
- the robot moves one step west (←).
Irene has asked for your programming help. What is the smallest number of instructions needed to add to the end of the sequence so that the robot finishes where it started?
Input
The first line of input contains the single integer $K$.
The second line of input contains a string of $K$ characters, the sequence of instructions.
The second line of input contains a string of $K$ characters, the sequence of instructions.
Output
Your program should output a single integer, the fewest instructions you need to add to the end
of the sequence.
Constraints
$1\leq K \leq 10^5$
Sample 1 Input
5
ENNEE
Sample 1 Output
5
Sample 2 Input
7
EEWWWWE
Sample 2 Output
1
Sample 3 Input
8
SWWNENNS
Sample 3 Output
2
4
NESW
0