
For Solution
Click Here!
The Rumbling is a hypothetical cataclysmic event involving Karl Fritz’s Wall Titans marching across the Earth, destroying all life upon it. Eren Yeager who possesses the Founding Titan has decided to begin The Rumbling to show the true power of the Eldians to the rest of the world. The Rumbling solution codechef
 There are NN Titans standing in a line from west to east. Each of the Titans is facing one of the four directions i.e., North, South, East, or West, represented by uppercase English letters ‘N’, ‘S’, ‘E’, and ‘W’ respectively.
 A Titan can rotate on the spot where it is standing. It requires XX units of energy to rotate 9090 degrees clockwise, and YY units of energy to rotate 9090 degrees anticlockwise.
 For the activation of The Rumbling, all the Titans must face Eren Yeager.
So, Eren wants to position himself on the WestEast line (on which other Titans are standing). He can either stand to the left of all Titans, in between two consecutive Titans, or to the right of all Titans. He wants to choose a position that minimizes the units of energy required by all the Titans to rotate and face him. Find the minimum units of energy required by all the Titans for the Activation of the Rumbling in the optimal configuration.
Input Format The Rumbling solution codechef
 The first line consists of TT, the number of test cases. Description of the test cases follow.
 The first line of each test case will contain NN, the number of Titans.
 The second line of each test case will contain a string SS of length NN, where the ithith character represents the directions faced by the ithith Titan.
 The third line of each test case will contain two spaceseparated integers, the values of XX and YY.
Output Format
For each test case, output a single line containing one integer, the answer to that test case.
Constraints The Rumbling solution codechef
 1≤T≤10001≤T≤1000
 1≤N≤2∗1051≤N≤2∗105
 1≤X,Y≤1091≤X,Y≤109
 SS contains characters from {‘N’, ‘S’, ‘E’, ‘W’} only.
 Sum of NN over all test cases doesn’t exceed 106106
Sample Input 1
1
5
SENWS
2 1
Sample Output 1 The Rumbling solution codechef
4
Explanation
 One valid configuration would be as follows: EE⋅WWWEE⋅WWW, where ⋅⋅ represents the position of Eren Yeager.
 The first and the second Titans will face Eren at East from the left while the third, fourth, and the fifth Titans will face Eren at West from the right.
 It takes 11 unit of energy for the first Titan to move towards East by rotating 9090 degrees anticlockwise.
 The second Titan is already facing East, so it costs him 00 units of energy to stay that way.
 It takes 11 unit of energy for the third Titan to move towards West by rotating 9090 degrees anticlockwise.
 The fourth Titan is already facing West, so it costs him 00 units of energy to stay that way.
 It takes 22 units of energy for the fifth Titan to move towards West by rotating 9090 degrees clockwise.
 So, it takes the Titans 44 units of energy overall to face Eren Yeager, and activate The Rumbling!

For Solution
Click Here!