{"trustable":false,"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\"\u003e\r\n\tThe 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 /\u003e\r\n\tThe great hall is represented as a two dimensional grid of R \u0026times; C cells. Some cells are already occupied with the museum\u0026rsquo;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 /\u003e\r\n\tcan 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 /\u003e\r\n\tSurveying all the artifacts in the great hall you figured out that the critical points of any artifact (marked by a \u003cimg src\u003d\"http://acm.hdu.edu.cn/data/images/chacha.jpg\" /\u003e ) are always a subset of the 12 neighboring cells as shown in the grid below.\u003cbr /\u003e\r\n\t\u003cbr /\u003e\r\n\t\u003ccenter\u003e\r\n\t\t\u003cimg src\u003d\"http://acm.hdu.edu.cn/data/images/C277-1010-1.jpg\" /\u003e\u003c/center\u003e\r\n\t\u003cbr /\u003e\r\n\t\u003cbr /\u003e\r\n\tAccordingly, the type of an artifact can be specified as a non-negative integer where the \u003cspan data-scayt_word\u003d\"i-th\" data-scaytid\u003d\"2\"\u003ei-th\u003c/span\u003e 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\r\n\t\u003cbr /\u003e\r\n\t\u003ccenter\u003e\r\n\t\t\u003cimg src\u003d\"http://acm.hdu.edu.cn/data/images/C277-1010-2.jpg\" /\u003e\u003c/center\u003e\r\n\t\u003cbr /\u003e\r\n\t\u003cbr /\u003e\r\n\tYou 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.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003e\r\n\tYour program will be tested on one or more test cases. Each test case is specified using R+1 lines.\u003cbr /\u003e\r\n\tThe 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 \u003cspan data-scayt_word\u003d\"j-th\" data-scaytid\u003d\"1\"\u003ej-th\u003c/span\u003e integer of the \u003cspan data-scayt_word\u003d\"i-th\" data-scaytid\u003d\"3\"\u003ei-th\u003c/span\u003e row is -1 if cell (i, j) already contains one of the museum\u0026rsquo;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 /\u003e\r\n\tThe last line of the input file has two zeros.\u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003e\r\n\tFor each test case, print the following line:\u003cbr /\u003e\r\n\tk. G\u003cbr /\u003e\r\n\tWhere 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.\u003c/div\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003e\r\n\t\u003cpre\u003e\u003c/pre\u003e\r\n\t\u003cdiv style\u003d\"font-family:Courier New,Courier,monospace;\"\u003e\r\n\t\t\u003cpre\u003e1 3\r\n512 -1 2048\r\n2 3\r\n512 2560 2048\r\n512 2560 2048\r\n0 0\u003c/pre\u003e\r\n\t\u003c/div\u003e\r\n\u003c/div\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003e\r\n\t\u003cpre\u003e\u003c/pre\u003e\r\n\t\u003cdiv style\u003d\"font-family:Courier New,Courier,monospace;\"\u003e\r\n\t\t\u003cpre\u003e1. 0\r\n2. 2\r\n\r\n\u003c/pre\u003e\r\n\t\u003c/div\u003e\r\n\u003c/div\u003e"}}]}