Figurines
InterviewTime limit2sMemory limit1024 MB
Given n figurines each facing N, S, W, or E, find the fewest turns needed to make all of them face the same direction.
- Level
Easy2 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Statement
Nolik got into trouble again. This time he messed up Dim Dimych's collection of figurines. Dim Dimych cares a lot about these figurines, so he would be very upset to see them in such a mess. Simka decided to fix everything quickly.
After Nolik played with the figurines, each one was standing on a shelf facing one of four directions: north, south, west, or east. To fix the situation, Simka decided to turn some of the figurines so that all of them face the same direction. In one second, Simka can change the direction of one figurine. Help Simka find the minimum time she needs to make all figurines face the same direction.
Input
The first line contains the number of figurines (). The second line contains a string of length that gives the directions of the figurines. Each character is N, S, W, or E.
Output
Print the minimum time Simka needs to make all figurines face the same direction.