{"problem":{"name":"Swap if Equal Length and Sum","description":{"content":"You are given integer sequences $A=(A_1,A_2,\\dots,A_N),\\; B=(B_1,B_2,\\dots,B_N)$ of length $N$ consisting of $0$ and $1$. Let $A[i,j]$ denote the contiguous subsequence from the $i$\\-th through $j$\\-t","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"agc074_b"},"statements":[{"statement_type":"Markdown","content":"You are given integer sequences $A=(A_1,A_2,\\dots,A_N),\\; B=(B_1,B_2,\\dots,B_N)$ of length $N$ consisting of $0$ and $1$. Let $A[i,j]$ denote the contiguous subsequence from the $i$\\-th through $j$\\-th elements of sequence $A$. If $i>j$, $A[i,j]$ is a sequence of length $0$. You can perform the following operation on $A$ at most $\\lfloor\\frac{N}{2}\\rfloor$ times:\n\n*   Choose four integers $a,b,c,d$ that satisfy the following three conditions:\n    *   $1 \\leq a \\leq b < c \\leq d \\leq N$\n    *   $b-a=d-c$\n    *   $\\sum_{i=a}^{b}{A_i}=\\sum_{i=c}^{d}{A_i}$\n*   Swap $A[a,b]$ and $A[c,d]$. More precisely, replace $A$ with the concatenation of $A[1,a-1]$, $A[c,d]$, $A[b+1,c-1]$, $A[a,b]$, $A[d+1,N]$ in this order.\n\nDetermine whether it is possible to make $A$ match $B$, and if possible, construct one sequence of operations.\nSolve $T$ test cases per input.\n\n## Constraints\n\n*   $1 \\leq T \\leq 25000$\n*   $2 \\leq N \\leq 2 \\times 10^5$\n*   $0 \\leq A_i \\leq 1$\n*   $0 \\leq B_i \\leq 1$\n*   The sum of $N$ over all test cases is at most $2\\times 10^5$.\n*   All input values are integers.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$T$\n$case_1$\n$case_2$\n$\\vdots$\n$case_T$\n\nEach case is given in the following format:\n\n$N$\n$A_1$ $A_2$ $\\dots$ $A_N$\n$B_1$ $B_2$ $\\dots$ $B_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"agc074_b","tags":[],"sample_group":[["3\n8\n1 0 0 1 0 1 0 1\n0 0 1 1 1 0 1 0\n2\n0 0\n1 0\n3\n1 1 1\n1 1 1","Yes\n2\n3 4 6 7\n1 4 5 8\nNo\nYes\n0\n\nIn the first test case, $A$ is initially $(1,0,0,1,0,1,0,1)$.  \nPerforming the operation with $(a,b,c,d)=(3,4,6,7)$ changes $A$ to $(1,0,1,0,0,0,1,1)$.  \nThen, performing the operation with $(a,b,c,d)=(1,4,5,8)$ changes $A$ to $(0,0,1,1,1,0,1,0)$, which matches $B$.  \nIn the second test case, it is impossible to make $A$ match $B$.  \nIn the third test case, $A$ already matches $B$ from the beginning."]],"created_at":"2026-03-03 11:01:13"}}