Buttons

All submissions for this problem are available.
Each cell of an N x N grid is either a 0 or a 1. You are given two such N x N grids, the initial grid and the final grid. There is a button against each row and each column of the initial N x N grid. Pressing a rowbutton toggles the values of all the cells in that row, and pressing a columnbutton toggles the values of all the cells in that column. You are required to find the minimum number of button presses required to transform the grid from the initial configuration to the final configuration, and the buttons that must be pressed in order to make this transformation.
Edit: When the initial and the final configurations are the same, print "0".
Input
The first line contains t, the number of test cases (about 10). Then t test cases follow.
Each test case has the following form:
* The first line contains n, the size of the board (1 ≤ n ≤ 1000).
* n lines follow. The ith line contains n space separated integers representing the ith row of the initial grid. Each integer is either a 0 or a 1.
* n lines follow, representing the final grid, in the same format as above.
Output
For each test case, output the number of rowbutton presses, followed by the row buttons that must be pressed. Print the number of columnbutton presses next, followed by 0indexed indices of the column buttons that must be pressed. The total number of button presses must be minimized.
Output "1" if it is impossible to achieve the final configuration from the initial configuration. If there is more than one solution, print any one of them.
Example
Input: 1 3 0 0 0 1 1 0 1 1 0 1 1 0 1 1 1 1 1 1 Output: 1 0 1 2
Author:  admin 
Tags  admin 
Date Added:  17072009 
Time Limit:  0.607925 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, PERL6, TEXT, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 