{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eThe great hall of the national museum has been robbed few times recently. Everyone is now worried about the security of the treasures on display. To help secure the hall, the museum contracted with a private security company to provide additional guards to stay in the great hall and keep an eye on the ancient artifacts. The museum would like to hire the minimum number of additional guards so that the great hall is secured.\u003cbr\u003eThe great hall is represented as a two dimensional grid of R × C cells. Some cells are already occupied with the museum’s guards. All remaining cells are occupied by artifacts of different types (statues, sculptures, . . . etc.) which can be replaced by new hired guards. For each artifact, few other cells in the hall are identified as critical points of the artifact depending on the artifact value, type of vault it is kept inside, and few other factors. In other words, if this artifact is going to stay in the hall then all of its critical points must have guards standing on them. A guard standing in a critical position of multiple artifacts can keep an eye on them all. A guard, however,\u003cbr\u003ecan not stand in a cell which contains an artifact (instead, you may remove the artifact to allow the guard to stay there). Also you can not remove an artifact and leave the space free (you can only replace an artifact with a new hired guard).\u003cbr\u003eSurveying all the artifacts in the great hall you figured out that the critical points of any artifact (marked by a \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/3dd598e2e6a40bd89b0475af33bff064?v\u003d1714356836\"\u003e ) are always a subset of the 12 neighboring cells as shown in the grid below.\u003cbr\u003e\u003cbr\u003e\u003ccenter\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/63886bc7506ee6cd2bdb99f0581ac02b?v\u003d1714356836\"\u003e\u003c/center\u003e \u003cbr\u003e\u003cbr\u003eAccordingly, the type of an artifact can be specified as a non-negative integer where the i-th bit is 1 only if critical point number i from the picture above is a critical point of that artifact. For example an artifact of type 595 (in binary 1001010011) can be pictured as shown in the figure below. Note that bits are numbered from right to left (the right-most bit is bit number 1.) If a critical point of an artifact lies outside the hall grid then it is considered secure.\u003cbr\u003e\u003cbr\u003e\u003ccenter\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/ef0422f979a56400533e0074b5c0f39c?v\u003d1714356836\"\u003e\u003c/center\u003e \u003cbr\u003e\u003cbr\u003eYou are given the layout of the great hall and are asked to find the minimum number of additional guards to hire such that all remaining artifacts are secured.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"Your program will be tested on one or more test cases. Each test case is specified using R+1 lines.\u003cbr\u003eThe first line specifies two integers (1\u0026lt;\u003d R,C \u0026lt;\u003d 50) which are the dimensions of the museum hall. The next R lines contain C integers separated by one or more spaces. The j-th integer of the i-th row is -1 if cell (i, j) already contains one of the museum’s guards, otherwise it contains an integer (0 \u0026lt;\u003d T \u0026lt;\u003d 2\u003csup\u003e12\u003c/sup\u003e) representing the type of the artifact in that cell.\u003cbr\u003eThe last line of the input file has two zeros.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, print the following line:\u003cbr\u003ek. G\u003cbr\u003eWhere k is the test case number (starting at one,) and G is the minimum number of additional guards to hire such that all remaining artifacts are secured.\u003cbr\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1 3\r\n512 -1 2048\r\n2 3\r\n512 2560 2048\r\n512 2560 2048\r\n0 0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1. 0\r\n2. 2\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cbr\u003eThe picture below shows the solution of the second test case where the two artifacts in the middle are replaced by guards.\u003cbr\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/01c71460537fc914b423586ccd0b0a02?v\u003d1714356836\"\u003e\u003cbr\u003e"}}]}