Codechef Code Drive Division 3 Solutions
Code Drive Division 3
Game between friends
Nitin and Sobhagya were playing a game with coins. If Sobhagya has more coins then he is winning, otherwise Nitin is winning. Note that this means if both Nitin and Sobhagya have the same number of coins, then Nitin is winning.
Initially Nitin has coins while Sobhagya has coins. Then Ritik came and gave his coins to the player who is not winning currently, after which Satyarth came and repeated the same process (gave his coins to the player who is not winning currently).
Find the final winner of the game.
Input Format
- The first line of the input contains an integer - the number of test cases. The test cases then follow.
- The only line of each test case contains four space-separated integers , , , and .
Output Format
For each test case, output on a single line N
if Nitin is the final winner of the game, or S
if Sobhagya is the final winner of the game.
Constraints
Sample Input 1
3
2 3 4 5
3 3 3 3
2 3 1 2
Sample Output 1
S
N
S
Explanation
- Test case :
- Initially, Nitin has coins and Sobhagya has coins, so Sobhagya is winning.
- Then, Ritik gives his coins to Nitin. Now Nitin has coins and Sobhagya has coins, so Nitin is winning.
- Then, Satyarth gives his coins to Sobhagya. Finally Nitin has coins and Sobhagya has coins, so Sobhagya is the final winner.
- Test case :
- Initially, Nitin has coins and Sobhagya has coins, so Nitin is winning.
- Then, Ritik gives his coins to Sobhagya. Now Nitin has coins and Sobhagya has coins, so Sobhagya is winning.
- Then, Satyarth gives his coins to Nitin. Finally Nitin has coins and Sobhagya has coins, so Nitin is the final winner.
Favourite String of Chef
A string is called Chef's favourite if every substring chef
in must have a substring code
before it.
You are given a string of size that contains both code
and chef
as a substring. Please determine if is Chef's favourite.
Note: A substring is a continuous part of string which can be obtained by deleting some (may be none) character's from the beginning and some (may be none) character's from the end.
Input Format
- The first line of the input contains an integer - the number of test cases. The test cases then follow.
- The first line of each test contains an integer - the size of the string.
- The second line of each test contains a string .
Output Format
For each test case, output on a single line AC
if is Chef's favourite, or WA
otherwise.
Constraints
- consists only of lowercase English characters
- Both
code
andchef
appear as a substring at least once in
Sample Input 1
4
8
codechef
8
chefcode
14
sxycodeghychef
21
sxychefvsvcodehghchef
Sample Output 1
AC
WA
AC
WA
Explanation
- Test case : Substring
code
is present beforechef
. - Test case : Substring
code
is not present beforechef
. - Test case : Substring
code
is present beforechef
. - Test case : There is no
code
substring present before the first occurrence ofchef
.
Count Number of Peaks
You are given an integer where . Consider any array with length where each element can either be , , or , we define as the number of extrema in . You need to find the sum of over all possible arrays .
Note:
- In an array , we consider as an extremum if it is strictly greater than both of its neighbors (i.e. and ), or if it is strictly smaller than both of its neighbors (i.e. and ). Note that first and last elements are not counted as extremum.
- Extrema is the plural of extremum.
Input Format
- The first line of the input contains an integer - the number of test cases. The test cases then follow.
- The only line of each test case contains one integer .
Output Format
For each test case, output on a single the sum of over all possible arrays .
Constraints
Sample Input 1
3
1
3
5
Sample Output 1
0
10
270
Explanation
- Test case :
- . Then .
- . Then .
- . Then .
Therefore the answer is .
- Test case : There are arrays with :
- .
- .
- .
- .
- .
- .
- .
- .
- .
- .
The remaining 's has . Therefore the answer is .