🏡 index : github.com/captn3m0/codechef.git

---
{"category_name":"medium","problem_code":"STRFLIP2","problem_name":"Convert Strings by Flips 2","problemComponents":{"constraints":"- $1 \\leq T \\leq 2000$\n- $20 \\leq N \\leq 10^3$\n- The sum of $N$ over all testcases does not exceed $5000$\n- $|A| = |B| = N$\n- $A$ and $B$ are binary strings, i.e, contain only $0$ and $1$.\n- At most $\\lfloor N/2 \\rfloor + 10$ moves can be made for each testcase.","constraintsState":true,"subtasks":"","subtasksState":false,"inputFormat":"- The first line of input contains a single integer $T$, denoting the number of test cases. The description of $T$ test cases follows.\n- Each test case consists of three lines.\n- The first line of each test case contains a single integer $N$, the size of the strings.\n- The second line of each test case contains $A$, a binary string with $N$ characters.\n- The third line of each test case contains $B$, a binary string with $N$ characters.","inputFormatState":true,"outputFormat":"- For each test case, print the answer starting from a new line in the following format:\n- In the first line, print $-1$ if it is impossible to convert $A$ to $B$. Otherwise, print a single non-negative integer $K$ — the number of moves that your solution requires.\n- Use the next $K$ lines to describe your sequence of moves, in the same order they are to be performed.\n- The $i^{th}$ of these $K$ lines should contain two integers $L_i$ and $R_i$, denoting the starting and ending positions of the substring chosen in the $i^{th}$ operation.\n- Note that the following conditions must be satisfied:\n    - $0 \\leq K \\leq \\lfloor N/2 \\rfloor + 10$\n    - $1 \\leq L_i \\leq R_i \\leq N$ for each valid $i$\n    - Each substring $A[L_i : R_i]$ must contain at least one \u0027$0$\u0027 and one \u0027$1$\u0027.","outputFormatState":true,"sampleTestCases":{"0":{"id":1,"input":"3\n5\n10110\n00100\n5\n00000\n11111\n2\n00\n00\n","output":"2\n1 4\n2 3\n-1\n0","explanation":"**Note:** The sample tests use strings of small lengths just to illustrate the problem, and will not be present in the actual tests. Every string in the actual test files will have a length of at least $20$, as stated by the constraints.\n\n**Test Case $1$:** The given string is $A = 10110$. Apart from the single character substrings and the substring $A[3:4] = 11$, all other substrings are valid first moves.\n\nThe sample output performs moves as follows:\n- First, flip the substring $A[1:4]$. Now, $A = 01000$.\n- Then, flip the substring $A[2:3]$. Now, $A = 00100$, which is the target string.\n\nNote that there are several other valid solutions, and any solution using no more than $\\lfloor 5/2 \\rfloor + 10 = 12$ moves will be accepted. For example, a sequence of $3$ moves is shown below:\n- Flip $A[1:5]$, giving $A = 01001$\n- Flip $A[4:5]$, giving $A = 01010$\n- Flip $A[2:4]$, giving $A = 00100$\n\n**Test Case 2:** The given string $A = 00000$ has no substring with both $0$ and $1$, consequently there are no moves possible. Therefore it is impossible to convert this string to $B = 11111$.\n\n**Test Case 3:** The given string $A = 00$ is already equal to $B$ and so no moves are required.","isDeleted":false}}},"video_editorial_url":"https://youtu.be/InmldNgvUkA","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"CPP17","5":"PYTH","6":"PYP3","7":"CS2","8":"ADA","9":"PYPY","10":"TEXT","11":"PAS fpc","12":"NODEJS","13":"RUBY","14":"PHP","15":"GO","16":"HASK","17":"TCL","18":"PERL","19":"SCALA","20":"LUA","21":"kotlin","22":"BASH","23":"JS","24":"LISP sbcl","25":"rust","26":"PAS gpc","27":"BF","28":"CLOJ","29":"R","30":"D","31":"CAML","32":"FORT","33":"ASM","34":"swift","35":"FS","36":"WSPC","37":"LISP clisp","38":"SQL","39":"SCM guile","40":"PERL6","41":"ERL","42":"CLPS","43":"ICK","44":"NICE","45":"PRLG","46":"ICON","47":"COB","48":"SCM chicken","49":"PIKE","50":"SCM qobi","51":"ST","52":"SQLQ","53":"NEM"},"max_timelimit":1,"source_sizelimit":50000,"problem_author":"utkarsh_adm","problem_tester":"aryanc403","date_added":"19-01-2022","tags":{"0":"constructive","1":"easy","2":"medium","3":"start22","4":"utkarsh_adm"},"problem_difficulty_level":"Unavailable","best_tag":"","editorial_url":"https://discuss.codechef.com/problems/STRFLIP2","time":{"view_start_date":1642613400,"submit_start_date":1642613400,"visible_start_date":1642613400,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=STRFLIP2","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
This is an example statement in markdown. This is the statement of the problem [TANDC](https://codechef.com/problems/TANDC) on CodeChef. The main statement starts with the next paragraph. Please make sure to remove this paragraph from your statement before publishing your problem. If your problem doesn't contain Subtasks, you should remove the section subtask too. We are using markdown the syntax of which can be seen [at](https://github.com/showdownjs/showdown/wiki/Showdown's-Markdown-syntax). We request you to not use any HTML tags in the statement, e.g. no p, ul, li, pre, br or b tags. If you face any issue, please contact admins or email us at help@codechef.com.

Tracy is teaching Charlie maths via a game called $N$-Cube, which involves three sections involving $N$.

Tracy gives Charlie a number $N$, and Charlie makes a list of $N$-th powers of integers in increasing order $1^N, 2^N, 3^N, \dot, \text{so on}$. This teaches him exponentiation.

Then Charlie performs the following subtraction game $N$ times: Take all pairs of consecutive numbers in the list and take their difference. These differences then form the new list for the next iteration of the game. Eg, if $N$ was 6, the list proceeds as $[1, 64, 729, 4096 ... ]$ to $[63, 685, 3367 ...]$, and so on $5$ more times.

After the subtraction game, Charlie has to correctly tell Tracy the $N$-th element of the list. This number is the *value of the game*.

After practice Charlie became an expert in the game. To challenge him more, Tracy will give two numbers $M$ (where $M$ is a prime) and $R$ instead of just a single number $N$, and the game must start from $M_R - 1$ instead of $N$. Since the *value of the game* can now become large, Charlie just have to tell the largest integer $K$ such that $M_K$ divides this number. Since even $K$ can be large, output $K$ modulo 1000000007 ($10^9 + 7$).

<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>