Two of your companions (we should signify them by [Math Processing Error] and [Math Processing Error]) are playing a game and you are going about as their seller. The principles of the game are as per the following: 

There are [Math Processing Error] section arrangements, indicated by [Math Processing Error]. 

At first, the two players don’t have any groupings. They play up to [Math Processing Error] turns. For each legitimate [Math Processing Error], in the [Math Processing Error]-th turn, you need to pick one player and give the section grouping [Math Processing Error] to this player. 

After each turn, in the event that it is conceivable to orchestrate all the arrangements of one part in some request and connect them so that the subsequent section grouping is non-vacant and adjusted, that player promptly dominates and the match closes. Note that it is incomprehensible for the two players to frame non-void adjusted groupings simultaneously. 

You like [Math Processing Error] more and henceforth need [Math Processing Error] to win. Locate the most modest number of turns you need so as to make [Math Processing Error] win or verify that it is difficult to accomplish this. 



A section succession is a self-assertive string containing just characters ‘(‘ and ‘)’. 

A reasonable section arrangement is one of the accompanying: 

An unfilled string. 

A link of two non-void adjusted section arrangements. 

A string shaped by adding ‘(‘ to the start and ‘)’ to the furthest limit of a decent section grouping. 



The principal line of the information contains a solitary whole number [Math Processing Error] meaning the quantity of experiments. The depiction of [Math Processing Error] experiments follows. 

The main line of each experiment contains a solitary whole number [Math Processing Error]. 

[Math Processing Error] lines follow. For each legitimate [Math Processing Error], the [Math Processing Error]-th of these lines contains a solitary string [Math Processing Error]. 



For each experiment, print a solitary line containing one whole number ― the most modest number of goes expected to make [Math Processing Error] win or [Math Processing Error] on the off chance that it is outlandish. 



[Math Processing Error] 

[Math Processing Error] 

[Math Processing Error] for each substantial [Math Processing Error] 


Model Input 






Model Output 



Model case 1: You can give [Math Processing Error] to [Math Processing Error] and [Math Processing Error] and [Math Processing Error] to [Math Processing Error].


March Long Challenge 2021 Solutions

April Long Challenge 2021 Solutions

Codechef Long Challenge Solutions

February Long Challenge 2021

1. Frog Sort Solution Codechef

2. Chef and Meetings Solution Codechef

3. Maximise Function Solution Codechef

4. Highest Divisor Solution Codechef

5. Cut the Cake Challenge Solution Codechef

6. Dream and the Multiverse Solution Codechef

7. Cell Shell Solution Codechef

8. Multiple Games Solution Codechef

9. Another Tree with Number Theory Solution Codechef

10. XOR Sums Solution Codechef

11. Prime Game Solution CodeChef

12. Team Name Solution Codechef

January Long Challenge 2021

November Challenge 2020 SOLUTION CodeChef

October Lunchtime 2020 CodeChef SOLUTIONS


Related :

Related :

Leave a Comment

1 × 5 =