You are given a twofold string S with length N and a number K, which is a divisor of N. A string is supposed to be K-foldable on the off chance that it very well may be changed to a string with length K by rehashing the accompanying cycle with no crashes (characterized beneath): 

Select the prefix of the current string S with length 2K. (Note that as long as the length of S is more prominent than K, this prefix consistently exists.) 

For every I (1≤i≤K), check if the 2K−i+1-th character of S is equivalent to the I-th character of S ― on the off chance that they are not equivalent, there is a crash and the cycle is invalid. 

Eradicate the prefix of S with length K. You will probably reorder the characters of S (conceivably leaving this string unaltered) so that the subsequent string S is a K-foldable string. Figure out how to do that or discover that it is incomprehensible. On the off chance that there are various arrangements, discover the lexicographically littlest modified string which is K-foldable. 



The main line of the info contains a solitary number T indicating the quantity of experiments. The portrayal of T experiments follows. 

The principal line of each experiment contains two space-isolated whole numbers N and K. 

The subsequent line contains a solitary string S with length N. 


Yield :For each experiment, print a solitary line containing the littlest improved string or the string “Inconceivable” in the event that it is difficult to revise S. 





N is detachable by K 

S contains just characters ‘0’ and ‘1’ 


Model Input 

8 2 


6 2 


Model Output 





Model case 1: If the given string “00011101” is modified to “01100110”, it becomes 2-foldable: 

At first, S is “01100110”. 

After the main collapsing, it becomes “100110”. 

After the subsequent collapsing, it becomes “0110”. 

After the third collapsing, it becomes “10”. This string has length 2, so we are finished. 

Model case 2: It is difficult to revise S into a 2-foldable string.



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

13 − 5 =