{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n #problem-body \u003e pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv id\u003d\"problem-body\"\u003e\n\t\u003cp\u003e\r\nYou are given a matrix of size\u0026nbsp;\u003cb\u003er\u003c/b\u003e x \u003cb\u003ec\u003c/b\u003e. Each of the elements can be either 0 or 1.\u0026nbsp; In each operation you can flip any element of this matrix, i.e. convert 0 to 1 or convert 1 to 0. Your goal is to convert the matrix such that -\r\n\u003c/p\u003e\r\n\u003col\u003e\r\n \u003cli\u003eEach of the rows will have the same number of 1s and\u003c/li\u003e\r\n \u003cli\u003eEach of the columns will have the same number of 1s.\u003c/li\u003e\r\n\u003c/ol\u003e\r\n\u003cp\u003eWhat is the minimum number of operations required to achieve this?\u003c/p\u003e\r\n\r\n\u003ch3\u003eInput\u003c/h3\u003e\r\n\u003cp\u003eInput starts with a positive integer\u0026nbsp;\u003cb\u003eT\u003c/b\u003e\u0026nbsp;(~1000) which indicates the number of inputs.\u003c/p\u003e\r\n\r\n\u003cp\u003eEach case starts with two integers\u0026nbsp;\u003cb\u003em\u003c/b\u003e\u0026nbsp;and\u0026nbsp;\u003cb\u003en\u003c/b\u003e\u0026nbsp;(1 \u0026lt;\u003d \u003cb\u003er\u003c/b\u003e, \u003cb\u003ec\u003c/b\u003e \u0026lt;\u003d 40), here\u0026nbsp;\u003cb\u003er\u003c/b\u003e\u0026nbsp;is the number of rows and\u0026nbsp;\u003cb\u003ec\u003c/b\u003e\u0026nbsp;is the number of columns of the matrix. Each of the next \u003cb\u003em\u003c/b\u003e lines will have \u003cb\u003en\u003c/b\u003e integers each, either 0 or 1.\u003c/p\u003e\r\n\r\n\u003ch3\u003eOutput\u003c/h3\u003e\r\n\u003cp\u003eFor each test case, output \u003ccode\u003e“Case #: R”\u003c/code\u003e in a single line, where \u003ccode\u003e#\u003c/code\u003e will be replaced by case number and\u0026nbsp;\u003cb\u003eR\u003c/b\u003e\u0026nbsp;will be replaced by the minimum number of steps required to achieve the target matrix. Replace\u0026nbsp;\u003cb\u003eR\u003c/b\u003e\u0026nbsp;by \u003ccode\u003e-1\u003c/code\u003e if it is not possible to reach target matrix.\u003c/p\u003e\r\n\r\n\u003ch3\u003eExample\u003c/h3\u003e\r\n\u003cstrong\u003eSample Input:\u003c/strong\u003e\u003cp\u003e\u003c/p\u003e\r\n\u003cpre\u003e\r\n3\r\n2 3\r\n111\r\n111\r\n3 3\r\n011\r\n011\r\n011\r\n2 3\r\n001\r\n000\u003c/pre\u003e\r\n\r\n\u003cp\u003e\u003cstrong\u003eSample Output:\u003c/strong\u003e\u003c/p\u003e\r\n\u003cpre\u003e\r\nCase 1: 0\r\nCase 2: 3\r\nCase 3: 1\u003c/pre\u003e\r\n\n\u003c/div\u003e"}}]}