{"id":183,"date":"2012-04-17T02:30:42","date_gmt":"2012-04-16T18:30:42","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=183"},"modified":"2012-04-17T17:53:30","modified_gmt":"2012-04-17T09:53:30","slug":"google-code-jam-2012-qualification-round","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/google-code-jam-2012-qualification-round\/","title":{"rendered":"Google Code Jam 2012 Qualification Round"},"content":{"rendered":"<h3>Brief description: <\/h3>\n<p>Problem D. Hall of Mirrors<br \/>\n\u7ed9\u5b9a\u4e00\u4e2a\u955c\u4e2d\u4e16\u754c.. . \u95ee\u70b9\u5149\u6e90\u5904\u6709\u591a\u5c11\u675f\u5149\u7ebf\u53ef\u4ee5\u5728 D \u5c04\u7a0b\u5185\u53cd\u5c04\u56de\u6765\u3002<br \/>\n\uff08 D <= 50\uff0c\u955c\u5b50\u53ea\u6709\u6c34\u5e73\u548c\u7ad6\u76f4\u4e24\u79cd.. .\uff09\n<!--more--><\/p>\n<h3>Analysis: <\/h3>\n<p>\u6bd4\u8d5b\u7684\u65f6\u5019\u5199\u7684\u662f\u53d1\u5c04\u6247\u5f62\u7684\u533a\u95f4\u3002\u3002\u3002\u5e76\u5728\u53cd\u5c04\u8fc7\u7a0b\u4e2d\u4e0d\u65ad\u7ec6\u5206\u7ec6\u5206\u3002\u3002\u3002<br \/>\n\uff08\u4ecd\u7136\u6709\u5f85\u5b9e\u73b0\u3002\u3002\uff09<\/p>\n<p>\u770b\u4e86\u4ee3\u7801\u53d1\u73b0\u5f88\u591a\u4eba\u5229\u7528\u8fd0\u52a8\u7684\u76f8\u5bf9\u6027\u3002\u3002\u5c06\u5e73\u9762\u6cbf\u7740\u955c\u9762\u7684\u53cd\u5c04\u65b9\u5411\u8fdb\u884c\u5e73\u94fa\u3002\u3002\u3002<br \/>\n\u8fd9\u6837\u5904\u7406\u540e\u53ef\u4ee5\u4fdd\u8bc1\u5149\u675f\u81ea\u59cb\u81ea\u7ec8\u662f\u4e00\u6761\u76f4\u7ebf\u3002\u3002\u3002\u3002\u5176\u5b9e\u4e0a\u8ff0\u601d\u8def\u7684\u771f\u6b63\u610f\u4e49\u662f\u5bf9\u89e3\u8fdb\u884c\u79bb\u6563\u5316\u3002\u3002\u3002<\/p>\n<p>\uff08\u88f8\u8ba1\u7b97\u51e0\u4f55\u65b9\u6cd5\u6bd4\u8f83\u65e0\u8111\u3002\u3002\u5c0f\u6570\u636e\u5927\u6982\u90fd\u8981\u8dd1 7 \u5206\u949f\u5427\u3002\u3002\u8fd8\u6709\u4e00\u4e9b\u6076\u5fc3\u7684\u7cbe\u5ea6\u95ee\u9898\u3002\u3002\uff09<br \/>\n\uff08\u3002\u3002\u3002\uff09<\/p>\n<pre class=\"brush: cpp; light: false; title: \u6807\u51c6\u8ba1\u7b97\u51e0\u4f55; toolbar: true; notranslate\" title=\"\u6807\u51c6\u8ba1\u7b97\u51e0\u4f55\">\r\n\/** ` Micro Mezzo Macro Flation -- Overheated Economy ., **\/\r\n\r\n#include &lt;algorithm&gt;\r\n#include &lt;iostream&gt;\r\n#include &lt;iomanip&gt;\r\n#include &lt;sstream&gt;\r\n#include &lt;cstring&gt;\r\n#include &lt;cstdio&gt;\r\n#include &lt;string&gt;\r\n#include &lt;vector&gt;\r\n#include &lt;bitset&gt;\r\n#include &lt;queue&gt;\r\n#include &lt;stack&gt;\r\n#include &lt;cmath&gt;\r\n#include &lt;ctime&gt;\r\n#include &lt;list&gt;\r\n#include &lt;set&gt;\r\n#include &lt;map&gt;\r\n\r\nusing namespace std;\r\n\r\n#define REP(i, n) for (int i=0;i&lt;int(n);++i)\r\n#define FOR(i, a, b) for (int i=int(a);i&lt;int(b);++i)\r\n#define DWN(i, b, a) for (int i=int(b-1);i&gt;=int(a);--i)\r\n#define REP_1(i, n) for (int i=1;i&lt;=int(n);++i)\r\n#define FOR_1(i, a, b) for (int i=int(a);i&lt;=int(b);++i)\r\n#define DWN_1(i, b, a) for (int i=int(b);i&gt;=int(a);--i)\r\n#define REP_C(i, n) for (int n____=int(n),i=0;i&lt;n____;++i)\r\n#define FOR_C(i, a, b) for (int b____=int(b),i=a;i&lt;b____;++i)\r\n#define DWN_C(i, b, a) for (int a____=int(a),i=b-1;i&gt;=a____;--i)\r\n#define REP_N(i, n) for (i=0;i&lt;int(n);++i)\r\n#define FOR_N(i, a, b) for (i=int(a);i&lt;int(b);++i)\r\n#define DWN_N(i, b, a) for (i=int(b-1);i&gt;=int(a);--i)\r\n#define REP_1_C(i, n) for (int n____=int(n),i=1;i&lt;=n____;++i)\r\n#define FOR_1_C(i, a, b) for (int b____=int(b),i=a;i&lt;=b____;++i)\r\n#define DWN_1_C(i, b, a) for (int a____=int(a),i=b;i&gt;=a____;--i)\r\n#define REP_1_N(i, n) for (i=1;i&lt;=int(n);++i)\r\n#define FOR_1_N(i, a, b) for (i=int(a);i&lt;=int(b);++i)\r\n#define DWN_1_N(i, b, a) for (i=int(b);i&gt;=int(a);--i)\r\n#define REP_C_N(i, n) for (n____=int(n),i=0;i&lt;n____;++i)\r\n#define FOR_C_N(i, a, b) for (b____=int(b),i=a;i&lt;b____;++i)\r\n#define DWN_C_N(i, b, a) for (a____=int(a),i=b-1;i&gt;=a____;--i)\r\n#define REP_1_C_N(i, n) for (n____=int(n),i=1;i&lt;=n____;++i)\r\n#define FOR_1_C_N(i, a, b) for (b____=int(b),i=a;i&lt;=b____;++i)\r\n#define DWN_1_C_N(i, b, a) for (a____=int(a),i=b;i&gt;=a____;--i)\r\n\r\n#define ECH(it, A) for (typeof(A.begin()) it=A.begin(); it != A.end(); ++it)\r\n#define DO(n) while(n--)\r\n#define DO_C(n) int n____ = n; while(n____--)\r\n#define TO(i, a, b) int s_=a&lt;b?1:-1,b_=b+s_;for(int i=a;i!=b_;i+=s_)\r\n#define TO_1(i, a, b) int s_=a&lt;b?1:-1,b_=b;for(int i=a;i!=b_;i+=s_)\r\n#define SQZ(i, j, a, b) for (int i=int(a),j=int(b)-1;i&lt;j;++i,--j)\r\n#define SQZ_1(i, j, a, b) for (int i=int(a),j=int(b);i&lt;=j;++i,--j)\r\n#define REP_2(i, j, n, m) REP(i, n) REP(j, m)\r\n#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)\r\n\r\n#define ALL(A) A.begin(), A.end()\r\n#define LLA(A) A.rbegin(), A.rend()\r\n#define CPY(A, B) memcpy(A, B, sizeof(A))\r\n#define INS(A, P, B) A.insert(A.begin() + P, B)\r\n#define ERS(A, P) A.erase(A.begin() + P)\r\n#define BSC(A, X) find(ALL(A), X) \/\/ != A.end()\r\n#define CTN(T, x) (T.find(x) != T.end())\r\n#define SZ(A) int(A.size())\r\n#define PB push_back\r\n#define MP(A, B) make_pair(A, B)\r\n\r\n#define Rush int T____; RD(T____); DO(T____)\r\n#pragma comment(linker, &quot;\/STACK:36777216&quot;)\r\n\/\/#pragma GCC optimize (&quot;O2&quot;)\r\n#define Ruby system(&quot;ruby main.rb&quot;)\r\n#define Haskell system(&quot;runghc main.hs&quot;)\r\n#define Pascal system(&quot;fpc main.pas&quot;)\r\n\r\ntypedef long long LL;\r\ntypedef double DB;\r\ntypedef unsigned UINT;\r\ntypedef unsigned long long ULL;\r\n\r\ntypedef vector&lt;int&gt; VI;\r\ntypedef vector&lt;char&gt; VC;\r\ntypedef vector&lt;string&gt; VS;\r\ntypedef vector&lt;LL&gt; VL;\r\ntypedef vector&lt;DB&gt; VD;\r\ntypedef set&lt;int&gt; SI;\r\ntypedef set&lt;string&gt; SS;\r\ntypedef set&lt;LL&gt; SL;\r\ntypedef set&lt;DB&gt; SD;\r\ntypedef map&lt;int, int&gt; MII;\r\ntypedef map&lt;string, int&gt; MSI;\r\ntypedef map&lt;LL, int&gt; MLI;\r\ntypedef map&lt;DB, int&gt; MDI;\r\ntypedef map&lt;int, bool&gt; MIB;\r\ntypedef map&lt;string, bool&gt; MSB;\r\ntypedef map&lt;LL, bool&gt; MLB;\r\ntypedef map&lt;DB, bool&gt; MDB;\r\ntypedef pair&lt;int, int&gt; PII;\r\ntypedef pair&lt;int, bool&gt; PIB;\r\ntypedef vector&lt;PII&gt; VII;\r\ntypedef vector&lt;VI&gt; VVI;\r\ntypedef vector&lt;VII&gt; VVII;\r\ntypedef set&lt;PII&gt; SII;\r\ntypedef map&lt;PII, int&gt; MPIII;\r\ntypedef map&lt;PII, bool&gt; MPIIB;\r\n\r\n\/** I\/O Accelerator **\/\r\n\r\n\/* ... :&quot; We are I\/O Accelerator ... Use us at your own risk ;) ... &quot; .. *\/\r\n\r\ntemplate&lt;class T&gt; inline void RD(T &amp;);\r\ntemplate&lt;class T&gt; inline void OT(const T &amp;);\r\n\r\ninline int RD(){ int x; RD(x); return x;}\r\ntemplate&lt;class T&gt; inline T&amp; _RD(T &amp;x){ RD(x); return x;}\r\ninline void RC(char &amp;c){scanf(&quot; %c&quot;, &amp;c);}\r\ninline void RS(char *s){scanf(&quot;%s&quot;, s);}\r\n\r\ntemplate&lt;class T0, class T1&gt; inline void RD(T0 &amp;x0, T1 &amp;x1){RD(x0), RD(x1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2){RD(x0), RD(x1), RD(x2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3){RD(x0), RD(x1), RD(x2), RD(x3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5, T6 &amp;x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6);}\r\ntemplate&lt;class T0, class T1&gt; inline void OT(T0 &amp;x0, T1 &amp;x1){OT(x0), OT(x1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2){OT(x0), OT(x1), OT(x2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3){OT(x0), OT(x1), OT(x2), OT(x3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5, T6 &amp;x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}\r\n\r\ntemplate&lt;class T&gt; inline void RST(T &amp;A){memset(A, 0, sizeof(A));}\r\ntemplate&lt;class T0, class T1&gt; inline void RST(T0 &amp;A0, T1 &amp;A1){RST(A0), RST(A1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2){RST(A0), RST(A1), RST(A2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3){RST(A0), RST(A1), RST(A2), RST(A3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5, T6 &amp;A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}\r\n\r\ntemplate&lt;class T&gt; inline void CLR(T &amp;A){A.clear();}\r\ntemplate&lt;class T0, class T1&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1){CLR(A0), CLR(A1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2){CLR(A0), CLR(A1), CLR(A2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5, T6 &amp;A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);}\r\ntemplate&lt;class T&gt; inline void CLR(T &amp;A, int n){REP(i, n) CLR(A&#x5B;i]);}\r\ntemplate&lt;class T&gt; inline void FLC(T &amp;A, int x){memset(A, x, sizeof(A));}\r\ntemplate&lt;class T0, class T1&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, int x){FLC(A0, x), FLC(A1, x);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2){FLC(A0), FLC(A1), FLC(A2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3){FLC(A0), FLC(A1), FLC(A2), FLC(A3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5, T6 &amp;A6){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5), FLC(A6);}\r\n\r\ntemplate&lt;class T&gt; inline void SRT(T &amp;A){sort(ALL(A));}\r\ntemplate&lt;class T, class C&gt; inline void SRT(T &amp;A, C B){sort(ALL(A), B);}\r\n\r\n\/** Add - On **\/\r\n\r\nconst int MOD = 1000000007;\r\nconst int INF = 10009;\r\nconst DB EPS = 1e-9;\r\nconst DB OO = 1e15;\r\nconst DB PI = 3.14159265358979323846264;\/\/M_PI;\r\n\r\n\/\/ &lt;&lt;= ` 0. Daily Use .,\r\n\r\ntemplate&lt;class T&gt; inline void checkMin(T &amp;a,const T b){if (b&lt;a) a=b;}\r\ntemplate&lt;class T&gt; inline void checkMax(T &amp;a,const T b){if (b&gt;a) a=b;}\r\ntemplate &lt;class T, class C&gt; inline void checkMin(T&amp; a, const T b, C c){if (c(b,a)) a = b;}\r\ntemplate &lt;class T, class C&gt; inline void checkMax(T&amp; a, const T b, C c){if (c(a,b)) a = b;}\r\ntemplate&lt;class T&gt; inline T min(T a, T b, T c){return min(min(a, b), c);}\r\ntemplate&lt;class T&gt; inline T max(T a, T b, T c){return max(max(a, b), c);}\r\ntemplate&lt;class T&gt; inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}\r\ntemplate&lt;class T&gt; inline T sqr(T a){return a*a;}\r\ntemplate&lt;class T&gt; inline T cub(T a){return a*a*a;}\r\nint Ceil(int x, int y){return (x - 1) \/ y + 1;}\r\n\r\n\/\/ &lt;&lt;= ` 1. Bitwise Operation .,\r\n\r\ninline bool _1(int x, int i){return x &amp; 1&lt;&lt;i;}\r\ninline int _1(int i){return 1&lt;&lt;i;}\r\ninline int _U(int i){return _1(i) - 1;};\r\n\r\ninline int count_bits(int x){\r\n    x = (x &amp; 0x55555555) + ((x &amp; 0xaaaaaaaa) &gt;&gt; 1);\r\n    x = (x &amp; 0x33333333) + ((x &amp; 0xcccccccc) &gt;&gt; 2);\r\n    x = (x &amp; 0x0f0f0f0f) + ((x &amp; 0xf0f0f0f0) &gt;&gt; 4);\r\n    x = (x &amp; 0x00ff00ff) + ((x &amp; 0xff00ff00) &gt;&gt; 8);\r\n    x = (x &amp; 0x0000ffff) + ((x &amp; 0xffff0000) &gt;&gt; 16);\r\n    return x;\r\n}\r\n\r\ntemplate&lt;class T&gt; inline T low_bit(T x) {\r\n    return x &amp; -x;\r\n}\r\n\r\ntemplate&lt;class T&gt; inline T high_bit(T x) {\r\n    T p = low_bit(x);\r\n    while (p != x) x -= p, p = low_bit(x);\r\n    return p;\r\n}\r\n\r\n\/\/ &lt;&lt;= ` 2. Modular Arithmetic Basic .,\r\n\r\ninline void INC(int &amp;a, int b){a += b; if (a &gt;= MOD) a -= MOD;}\r\ninline int sum(int a, int b){a += b; if (a &gt;= MOD) a -= MOD; return a;}\r\ninline void DEC(int &amp;a, int b){a -= b; if (a &lt; 0) a += MOD;}\r\ninline int dff(int a, int b){a -= b; if (a &lt; 0) a  += MOD; return a;}\r\ninline void MUL(int &amp;a, int b){a = int((LL)a * b % MOD);}\r\ninline int pdt(int a, int b){return int((LL)a * b % MOD);}\r\n\r\n\/\/ &lt;&lt;= '9. Comutational Geometry .,\r\n\r\nstruct Po; struct Line; struct Seg;\r\n\r\ninline int sgn(DB x){return x &lt; -EPS ? -1 : x &gt; EPS;}\r\ninline int sgn(DB x, DB y){return sgn(x - y);}\r\n\r\nstruct Po{\r\n    DB x, y;\r\n    Po(DB _x = 0, DB _y = 0):x(_x), y(_y){}\r\n\r\n    friend istream&amp; operator &gt;&gt;(istream&amp; in, Po &amp;p){return in &gt;&gt; p.x &gt;&gt; p.y;}\r\n    friend ostream&amp; operator &lt;&lt;(ostream&amp; out, Po p){return out &lt;&lt; &quot;(&quot; &lt;&lt; p.x &lt;&lt; &quot;, &quot; &lt;&lt; p.y &lt;&lt; &quot;)&quot;;}\r\n\r\n    friend bool operator ==(Po, Po);\r\n    friend bool operator !=(Po, Po);\r\n    friend Po operator +(Po, Po);\r\n    friend Po operator -(Po, Po);\r\n    friend Po operator *(Po, DB);\r\n    friend Po operator \/(Po, DB);\r\n\r\n    bool operator &lt; (const Po &amp;rhs) const{return sgn(x, rhs.x) &lt; 0 || sgn(x, rhs.x) == 0 &amp;&amp; sgn(y, rhs.y) &lt; 0;}\r\n    Po&amp; operator +=(Po rhs){x += rhs.x, y += rhs.y;}\r\n    Po&amp; operator -=(Po rhs){x -= rhs.x, y -= rhs.y;}\r\n    Po&amp; operator *=(DB k){x *= k, y *= k;}\r\n    Po&amp; operator \/=(DB k){x \/= k, y \/= k;}\r\n\r\n    DB length_sqr(){return sqr(x) + sqr(y);}\r\n    DB length(){return sqrt(length_sqr());}\r\n\r\n    DB atan(){\r\n        return atan2(y, x);\r\n    }\r\n\r\n    void input(){\r\n        int _x, _y; scanf(&quot;%d %d&quot;, &amp;_x, &amp;_y);\r\n        x = _x, y = _y;\r\n    }\r\n};\r\n\r\nbool operator ==(Po a, Po b){return sgn(a.x - b.x) == 0 &amp;&amp; sgn(a.y - b.y) == 0;}\r\nbool operator !=(Po a, Po b){return sgn(a.x - b.x) != 0 || sgn(a.y - b.y) != 0;}\r\nPo operator +(Po a, Po b){return Po(a.x + b.x, a.y + b.y);}\r\nPo operator -(Po a, Po b){return Po(a.x - b.x, a.y - b.y);}\r\nPo operator *(Po a, DB k){return Po(a.x * k, a.y * k);}\r\nPo operator \/(Po a, DB k){return Po(a.x \/ k, a.y \/ k);}\r\n\r\nstruct Line{\r\n    Po a, b;\r\n    Line(Po _a = Po(), Po _b = Po()):a(_a), b(_b){}\r\n    Line(DB x0, DB y0, DB x1, DB y1):a(Po(x0, y0)), b(Po(x1, y1)){}\r\n    Line(Seg);\r\n\r\n    friend ostream&amp; operator &lt;&lt;(ostream&amp; out, Line p){return out &lt;&lt; p.a &lt;&lt; &quot;-&quot; &lt;&lt; p.b;}\r\n};\r\n\r\nstruct Seg{\r\n    Po a, b;\r\n    Seg(Po _a = Po(), Po _b = Po()):a(_a), b(_b){}\r\n    Seg(DB x0, DB y0, DB x1, DB y1):a(Po(x0, y0)), b(Po(x1, y1)){}\r\n    Seg(Line l);\r\n\r\n    friend ostream&amp; operator &lt;&lt;(ostream&amp; out, Seg p){return out &lt;&lt; p.a &lt;&lt; &quot;-&quot; &lt;&lt; p.b;}\r\n    DB length(){return (b - a).length();}\r\n};\r\n\r\nLine::Line(Seg l):a(l.a), b(l.b){}\r\nSeg::Seg(Line l):a(l.a), b(l.b){}\r\n\r\n#define innerProduct dot\r\n#define scalarProduct dot\r\n#define dotProduct dot\r\n#define outerProduct det\r\n#define crossProduct det\r\n\r\ninline DB dot(DB x1, DB y1, DB x2, DB y2){return x1 * x2 + y1 * y2;}\r\ninline DB dot(Po a, Po b){return dot(a.x, b.y, b.x, b.y);}\r\ninline DB dot(Po p0, Po p1, Po p2){return dot(p1 - p0, p2 - p0);}\r\ninline DB dot(Line l1, Line l2){return dot(l1.b - l1.a, l2.b - l2.a);}\r\ninline DB det(DB x1, DB y1, DB x2, DB y2){return x1 * y2 - x2 * y1;}\r\ninline DB det(Po a, Po b){return det(a.x, a.y, b.x, b.y);}\r\ninline DB det(Po p0, Po p1, Po p2){return det(p1 - p0, p2 - p0);}\r\ninline DB det(Line l1, Line l2){return det(l1.b - l1.a, l2.b - l2.a);}\r\n\r\ntemplate&lt;class T1, class T2&gt; inline DB dist(T1 x, T2 y){return sqrt(dist_sqr(x, y));}\r\n\r\ninline DB dist_sqr(Po a, Po b){return sqr(a.x - b.x) + sqr(a.y - b.y);}\r\ninline DB dist_sqr(Po p, Line l){Po v0 = l.b - l.a, v1 = p - l.a; return sqr(fabs(det(v0, v1))) \/ v0.length_sqr();}\r\ninline DB dist_sqr(Po p, Seg l){\r\n    Po v0 = l.b - l.a, v1 = p - l.a, v2 = p - l.b;\r\n    if (sgn(dot(v0, v1)) * sgn(dot(v0, v2)) &lt;= 0) return dist_sqr(p, Line(l));\r\n    else return min(v1.length_sqr(), v2.length_sqr());\r\n}\r\n\r\ninline DB dist_sqr(Line l, Po p){\r\n    return dist_sqr(p, l);\r\n}\r\n\r\ninline DB dist_sqr(Line l1, Line l2){\r\n    if (sgn(det(l1, l2)) != 0) return 0;\r\n    return dist_sqr(l1.a, l2);\r\n}\r\ninline DB dist_sqr(Line l1, Seg l2){\r\n    Po v0 = l1.b - l1.a, v1 = l2.a - l1.a, v2 = l2.b - l1.a; DB c1 = det(v0, v1), c2 = det(v0, v2);\r\n    return sgn(c1) != sgn(c2) ? 0 : sqr(min(fabs(c1), fabs(c2))) \/ v0.length_sqr();\r\n}\r\n\r\ninline DB dist_sqr(Seg l, Po p){\r\n    return dist_sqr(p, l);\r\n}\r\n\r\ninline DB dist_sqr(Seg l1, Line l2){\r\n    return dist_sqr(l2, l1);\r\n}\r\n\r\nbool isIntersect(Seg l1, Seg l2){\r\n\r\n    \/\/if (l1.a == l2.a || l1.a == l2.b || l1.b == l2.a || l1.b == l2.b) return true;\r\n\r\n    return\r\n        min(l1.a.x, l1.b.x) &lt;= max(l2.a.x, l2.b.x) &amp;&amp;\r\n        min(l2.a.x, l2.b.x) &lt;= max(l1.a.x, l1.b.x) &amp;&amp;\r\n        min(l1.a.y, l1.b.y) &lt;= max(l2.a.y, l2.b.y) &amp;&amp;\r\n        min(l2.a.y, l2.b.y) &lt;= max(l1.a.y, l1.b.y) &amp;&amp;\r\n    sgn( det(l1.a, l2.a, l2.b) ) * sgn( det(l1.b, l2.a, l2.b) ) &lt;= 0 &amp;&amp;\r\n    sgn( det(l2.a, l1.a, l1.b) ) * sgn( det(l2.b, l1.a, l1.b) ) &lt;= 0;\r\n\r\n}\r\n\r\ninline DB dist_sqr(Seg l1, Seg l2){\r\n    if (isIntersect(l1, l2)) return 0;\r\n    else return min(dist_sqr(l1.a, l2), dist_sqr(l1.b, l2), dist_sqr(l2.a, l1), dist_sqr(l2.b, l1));\r\n}\r\n\r\ninline bool isOnExtremePoint(const Po &amp;p, const Seg &amp;l){\r\n    return p == l.a || p == l.b;\r\n}\r\n\r\ninline bool isOnseg(const Po &amp;p, const Seg &amp;l){\r\n\r\n    \/\/if (p == l.a || p == l.b) return false;\r\n\r\n    return sgn(det(p, l.a, l.b)) == 0 &amp;&amp;\r\n        sgn(l.a.x, p.x) * sgn(l.b.x, p.x) &lt;= 0 &amp;&amp; sgn(l.a.y, p.y) * sgn(l.b.y, p.y) &lt;= 0;\r\n}\r\n\r\n\r\n\r\ninline Po intersect(const Line &amp;l1, const Line &amp;l2){\r\n    return l1.a + (l1.b - l1.a) * (det(l2.a, l1.a, l2.b) \/ det(l2, l1));\r\n}\r\n\r\n\/\/ perpendicular foot\r\ninline Po intersect(const Po &amp; p, const Line &amp;l){\r\n    return intersect(Line(p, p + Po(l.a.y - l.b.y, l.b.x - l.a.x)), l);\r\n}\r\n\r\ninline Po rotate(Po p, DB alpha, Po o = Po()){\r\n    p.x -= o.x, p.y -= o .y;\r\n    return Po(p.x * cos(alpha) - p.y * sin(alpha), p.y * cos(alpha) + p.x * sin(alpha)) + o;\r\n}\r\n\r\n\/\/ &lt;&lt;= ' 0. I\/O Accelerator interface .,\r\n\r\ntemplate&lt;class T&gt; inline void RD(T &amp;x){\r\n    \/\/cin &gt;&gt; x;\r\n    scanf(&quot;%d&quot;, &amp;x);\r\n    \/\/char c; for (c = getchar(); c &lt; '0'; c = getchar()); x = c - '0'; for (c = getchar(); c &gt;= '0'; c = getchar()) x = x * 10 + c - '0';\r\n    \/\/char c; c = getchar(); x = c - '0'; for (c = getchar(); c &gt;= '0'; c = getchar()) x = x * 10 + c - '0';\r\n}\r\n\r\nint ____Case;\r\ntemplate&lt;class T&gt; inline void OT(const T &amp;x){\r\n    printf(&quot;Case #%d: &quot;, ++____Case);\r\n    printf(&quot;%d&quot;, x);\r\n    puts(&quot;&quot;);\r\n}\r\n\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 39;\r\nchar Map&#x5B;N]&#x5B;N], tmp&#x5B;N]&#x5B;N];\r\nint n, m, D, X0, Y0, res;\r\n\r\nvector&lt;Line&gt; mirror;\r\n\r\nstruct ray{\r\n    Po p; int dx, dy;\r\n    ray(){}\r\n    ray(Po _p, int _dx, int _dy):p(_p), dx(_dx), dy(_dy){}\r\n    Po p_(){\r\n        return Po(p.x + 2e2*dx, p.y + 2e2*dy);\r\n    }\r\n} cur;\r\n\r\nvector&lt;pair&lt;Po, bool&gt; &gt; L; vector&lt;DB&gt; P;\r\nDB _d, d; Po O;\r\n\r\n\r\ninline Po lb(int x, int y){\r\n    return Po(x * 2 + 2, y * 2);\r\n}\r\n\r\ninline Po rb(int x, int y){\r\n    return Po(x * 2 + 2, y * 2 + 2);\r\n}\r\n\r\ninline Po lu(int x, int y){\r\n    return Po(x * 2, y * 2);\r\n}\r\n\r\ninline Po ru(int x, int y){\r\n    return Po(x * 2, y * 2 + 2);\r\n}\r\n\r\ninline Po mm(int x, int y){\r\n    return Po(x * 2 + 1, y * 2 + 1);\r\n}\r\n\r\nvoid init(){\r\n\r\n    RST(Map); CLR(mirror); RD(n, m, D); d = D * 2; REP_2(i, j, n, m){\r\n        RC(Map&#x5B;i]&#x5B;j]); if (Map&#x5B;i]&#x5B;j] == 'X') X0 = i, Y0 = j, Map&#x5B;i]&#x5B;j] = '.';\r\n    }\r\n\r\n    int _i, _j; CPY(tmp, Map); REP_2(i, j, n, m) if (tmp&#x5B;i]&#x5B;j] == '#'){\r\n        _j = j, tmp&#x5B;i]&#x5B;j] = '.';\r\n        while (tmp&#x5B;i]&#x5B;j+1] == '#'){\r\n            tmp&#x5B;i]&#x5B;++j] = '.';\r\n        }\r\n        mirror.PB(Line(lb(i, _j), rb(i, j)));\r\n        mirror.PB(Line(lu(i, _j), ru(i, j)));\r\n    }\r\n\r\n    CPY(tmp, Map); REP_2(j, i, m, n) if (tmp&#x5B;i]&#x5B;j] == '#'){\r\n        _i = i, tmp&#x5B;i]&#x5B;j] = '.';\r\n        while (tmp&#x5B;i+1]&#x5B;j] == '#'){\r\n            tmp&#x5B;++i]&#x5B;j] = '.';\r\n        }\r\n        mirror.PB(Line(lu(_i, j), lb(i, j)));\r\n        mirror.PB(Line(ru(_i, j), rb(i, j)));\r\n    }\r\n\r\n\r\n\/*\r\n    REP(i, SZ(mirror)){\r\n        cout &lt;&lt; mirror&#x5B;i] &lt;&lt; endl;\r\n    }\r\n\r\n    cout &lt;&lt; &quot;----&quot; &lt;&lt; endl;\r\n*\/\r\n\r\n    O = mm(X0, Y0), res = 0;\r\n}\r\n\r\nbool comp(pair&lt;Po, bool&gt; a, pair&lt;Po, bool&gt; b){\r\n    return dist_sqr(cur.p, a.first) &lt;= dist_sqr(cur.p, b.first);\r\n}\r\n\r\nint main(){\r\n\r\n    freopen(&quot;D-large-practice.in&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n\r\n    Rush{\r\n\r\n        init(); FOR_1(i, -D, D) FOR_1(j, -D, D){\r\n\r\n            if (!i &amp;&amp; abs(j) != 1) continue;\r\n            if (!j &amp;&amp; abs(i) != 1) continue;\r\n            if (i &amp;&amp; j &amp;&amp; abs(__gcd(i, j)) != 1) continue;\r\n            if (sqr(i)+sqr(j) &gt; sqr(D)) continue;\r\n\r\n            cur = ray(O, i, j), _d = 0;\r\n\r\n            while (true){\r\n\r\n                Line l = Line(cur.p, cur.p_());\r\n\r\n                CLR(L, P); REP(ii, SZ(mirror)) if (!isOnseg(cur.p, mirror&#x5B;ii])){\r\n                    Po p = intersect(l, mirror&#x5B;ii]);\r\n                    if (isOnseg(p, l)){\r\n                        if (isOnExtremePoint(p, mirror&#x5B;ii])) P.PB(dist_sqr(cur.p, p));\r\n                        else if (isOnseg(p, mirror&#x5B;ii])) L.PB(MP(p, !sgn(mirror&#x5B;ii].a.x, mirror&#x5B;ii].b.x)));\r\n                    }\r\n                }\r\n\r\n                sort(ALL(L), comp), SRT(P);\r\n\r\n                if (!P.empty() &amp;&amp; sgn(P&#x5B;0], dist_sqr(cur.p, L&#x5B;0].first)) &lt; 0){\r\n\r\n                    bool bx = false, by = false; REP(ii, SZ(mirror)) if (!isOnseg(cur.p, mirror&#x5B;ii])){\r\n                        Po p = intersect(l, mirror&#x5B;ii]);\r\n                        if (isOnseg(p, l)){\r\n                            if (isOnExtremePoint(p, mirror&#x5B;ii])){\r\n                                if (!sgn(dist_sqr(cur.p, p), P&#x5B;0])){\r\n                                    if (!sgn(mirror&#x5B;ii].a.x, mirror&#x5B;ii].b.x)){\r\n                                        if ( (min(mirror&#x5B;ii].a.y, mirror&#x5B;ii].b.y) == p.y) ^ (j&lt;0) ) by = true;\r\n                                    }\r\n                                    else {\r\n                                        if ( (min(mirror&#x5B;ii].a.x, mirror&#x5B;ii].b.x) == p.x) ^ (i&lt;0) ) bx = true;\r\n                                    }\r\n                                }\r\n                            }\r\n                        }\r\n\r\n                        if (bx &amp;&amp; by) break;\r\n                    }\r\n\r\n                    if (bx &amp;&amp; by) break;\r\n                }\r\n\r\n\r\n                if (cur.p != O &amp;&amp; isOnseg(O, l) &amp;&amp; dist_sqr(cur.p, O) &lt; dist_sqr(cur.p, L&#x5B;0].first)){\r\n                    if ( sgn(_d + dist(cur.p, O), d) &lt;= 0) ++res;\r\n                    break;\r\n                }\r\n\r\n                _d += dist(cur.p, L&#x5B;0].first); if (sgn(_d, d) &gt;= 0) break;\r\n\r\n                cur.p = L&#x5B;0].first; if (SZ(L) &gt;= 2 &amp;&amp; !sgn(dist(cur.p, L&#x5B;0].first) , dist(cur.p, L&#x5B;1].first))){\r\n                    cur.dx = -cur.dx, cur.dy = -cur.dy;\r\n                }\r\n                else {\r\n                    if (L&#x5B;0].second) cur.dx = -cur.dx;\r\n                    else cur.dy = -cur.dy;\r\n                }\r\n            }\r\n        }\r\n\r\n        OT(res);\r\n        cerr &lt;&lt; &quot;Case: &quot; &lt;&lt; ____Case &lt;&lt; endl;\r\n    }\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; light: false; title: \u5fae\u64cd\u683c\u70b9; toolbar: true; notranslate\" title=\"\u5fae\u64cd\u683c\u70b9\">\r\n\/** ` Micro Mezzo Macro Flation -- Overheated Economy ., **\/\r\n\r\n#include &lt;algorithm&gt;\r\n#include &lt;iostream&gt;\r\n#include &lt;iomanip&gt;\r\n#include &lt;sstream&gt;\r\n#include &lt;cstring&gt;\r\n#include &lt;cstdio&gt;\r\n#include &lt;string&gt;\r\n#include &lt;vector&gt;\r\n#include &lt;bitset&gt;\r\n#include &lt;queue&gt;\r\n#include &lt;stack&gt;\r\n#include &lt;cmath&gt;\r\n#include &lt;ctime&gt;\r\n#include &lt;list&gt;\r\n#include &lt;set&gt;\r\n#include &lt;map&gt;\r\n\r\nusing namespace std;\r\n\r\n#define REP(i, n) for (int i=0;i&lt;int(n);++i)\r\n#define FOR(i, a, b) for (int i=int(a);i&lt;int(b);++i)\r\n#define DWN(i, b, a) for (int i=int(b-1);i&gt;=int(a);--i)\r\n#define REP_1(i, n) for (int i=1;i&lt;=int(n);++i)\r\n#define FOR_1(i, a, b) for (int i=int(a);i&lt;=int(b);++i)\r\n#define DWN_1(i, b, a) for (int i=int(b);i&gt;=int(a);--i)\r\n#define REP_C(i, n) for (int n____=int(n),i=0;i&lt;n____;++i)\r\n#define FOR_C(i, a, b) for (int b____=int(b),i=a;i&lt;b____;++i)\r\n#define DWN_C(i, b, a) for (int a____=int(a),i=b-1;i&gt;=a____;--i)\r\n#define REP_N(i, n) for (i=0;i&lt;int(n);++i)\r\n#define FOR_N(i, a, b) for (i=int(a);i&lt;int(b);++i)\r\n#define DWN_N(i, b, a) for (i=int(b-1);i&gt;=int(a);--i)\r\n#define REP_1_C(i, n) for (int n____=int(n),i=1;i&lt;=n____;++i)\r\n#define FOR_1_C(i, a, b) for (int b____=int(b),i=a;i&lt;=b____;++i)\r\n#define DWN_1_C(i, b, a) for (int a____=int(a),i=b;i&gt;=a____;--i)\r\n#define REP_1_N(i, n) for (i=1;i&lt;=int(n);++i)\r\n#define FOR_1_N(i, a, b) for (i=int(a);i&lt;=int(b);++i)\r\n#define DWN_1_N(i, b, a) for (i=int(b);i&gt;=int(a);--i)\r\n#define REP_C_N(i, n) for (n____=int(n),i=0;i&lt;n____;++i)\r\n#define FOR_C_N(i, a, b) for (b____=int(b),i=a;i&lt;b____;++i)\r\n#define DWN_C_N(i, b, a) for (a____=int(a),i=b-1;i&gt;=a____;--i)\r\n#define REP_1_C_N(i, n) for (n____=int(n),i=1;i&lt;=n____;++i)\r\n#define FOR_1_C_N(i, a, b) for (b____=int(b),i=a;i&lt;=b____;++i)\r\n#define DWN_1_C_N(i, b, a) for (a____=int(a),i=b;i&gt;=a____;--i)\r\n\r\n#define ECH(it, A) for (typeof(A.begin()) it=A.begin(); it != A.end(); ++it)\r\n#define DO(n) while(n--)\r\n#define DO_C(n) int n____ = n; while(n____--)\r\n#define TO(i, a, b) int s_=a&lt;b?1:-1,b_=b+s_;for(int i=a;i!=b_;i+=s_)\r\n#define TO_1(i, a, b) int s_=a&lt;b?1:-1,b_=b;for(int i=a;i!=b_;i+=s_)\r\n#define SQZ(i, j, a, b) for (int i=int(a),j=int(b)-1;i&lt;j;++i,--j)\r\n#define SQZ_1(i, j, a, b) for (int i=int(a),j=int(b);i&lt;=j;++i,--j)\r\n#define REP_2(i, j, n, m) REP(i, n) REP(j, m)\r\n#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)\r\n\r\n#define ALL(A) A.begin(), A.end()\r\n#define LLA(A) A.rbegin(), A.rend()\r\n#define CPY(A, B) memcpy(A, B, sizeof(A))\r\n#define INS(A, P, B) A.insert(A.begin() + P, B)\r\n#define ERS(A, P) A.erase(A.begin() + P)\r\n#define BSC(A, X) find(ALL(A), X) \/\/ != A.end()\r\n#define CTN(T, x) (T.find(x) != T.end())\r\n#define SZ(A) int(A.size())\r\n#define PB push_back\r\n#define MP(A, B) make_pair(A, B)\r\n\r\n#define Rush int T____; RD(T____); DO(T____)\r\n#pragma comment(linker, &quot;\/STACK:36777216&quot;)\r\n\/\/#pragma GCC optimize (&quot;O2&quot;)\r\n#define Ruby system(&quot;ruby main.rb&quot;)\r\n#define Haskell system(&quot;runghc main.hs&quot;)\r\n#define Pascal system(&quot;fpc main.pas&quot;)\r\n\r\ntypedef long long LL;\r\ntypedef double DB;\r\ntypedef unsigned UINT;\r\ntypedef unsigned long long ULL;\r\n\r\ntypedef vector&lt;int&gt; VI;\r\ntypedef vector&lt;char&gt; VC;\r\ntypedef vector&lt;string&gt; VS;\r\ntypedef vector&lt;LL&gt; VL;\r\ntypedef vector&lt;DB&gt; VD;\r\ntypedef set&lt;int&gt; SI;\r\ntypedef set&lt;string&gt; SS;\r\ntypedef set&lt;LL&gt; SL;\r\ntypedef set&lt;DB&gt; SD;\r\ntypedef map&lt;int, int&gt; MII;\r\ntypedef map&lt;string, int&gt; MSI;\r\ntypedef map&lt;LL, int&gt; MLI;\r\ntypedef map&lt;DB, int&gt; MDI;\r\ntypedef map&lt;int, bool&gt; MIB;\r\ntypedef map&lt;string, bool&gt; MSB;\r\ntypedef map&lt;LL, bool&gt; MLB;\r\ntypedef map&lt;DB, bool&gt; MDB;\r\ntypedef pair&lt;int, int&gt; PII;\r\ntypedef pair&lt;int, bool&gt; PIB;\r\ntypedef vector&lt;PII&gt; VII;\r\ntypedef vector&lt;VI&gt; VVI;\r\ntypedef vector&lt;VII&gt; VVII;\r\ntypedef set&lt;PII&gt; SII;\r\ntypedef map&lt;PII, int&gt; MPIII;\r\ntypedef map&lt;PII, bool&gt; MPIIB;\r\n\r\n\/** I\/O Accelerator **\/\r\n\r\n\/* ... :&quot; We are I\/O Accelerator ... Use us at your own risk ;) ... &quot; .. *\/\r\n\r\ntemplate&lt;class T&gt; inline void RD(T &amp;);\r\ntemplate&lt;class T&gt; inline void OT(const T &amp;);\r\n\r\ninline int RD(){ int x; RD(x); return x;}\r\ntemplate&lt;class T&gt; inline T&amp; _RD(T &amp;x){ RD(x); return x;}\r\ninline void RC(char &amp;c){scanf(&quot; %c&quot;, &amp;c);}\r\ninline void RS(char *s){scanf(&quot;%s&quot;, s);}\r\n\r\ntemplate&lt;class T0, class T1&gt; inline void RD(T0 &amp;x0, T1 &amp;x1){RD(x0), RD(x1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2){RD(x0), RD(x1), RD(x2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3){RD(x0), RD(x1), RD(x2), RD(x3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5, T6 &amp;x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6);}\r\ntemplate&lt;class T0, class T1&gt; inline void OT(T0 &amp;x0, T1 &amp;x1){OT(x0), OT(x1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2){OT(x0), OT(x1), OT(x2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3){OT(x0), OT(x1), OT(x2), OT(x3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5, T6 &amp;x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}\r\n\r\ntemplate&lt;class T&gt; inline void RST(T &amp;A){memset(A, 0, sizeof(A));}\r\ntemplate&lt;class T0, class T1&gt; inline void RST(T0 &amp;A0, T1 &amp;A1){RST(A0), RST(A1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2){RST(A0), RST(A1), RST(A2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3){RST(A0), RST(A1), RST(A2), RST(A3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5, T6 &amp;A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}\r\n\r\ntemplate&lt;class T&gt; inline void CLR(T &amp;A){A.clear();}\r\ntemplate&lt;class T0, class T1&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1){CLR(A0), CLR(A1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2){CLR(A0), CLR(A1), CLR(A2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5, T6 &amp;A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);}\r\ntemplate&lt;class T&gt; inline void CLR(T &amp;A, int n){REP(i, n) CLR(A&#x5B;i]);}\r\ntemplate&lt;class T&gt; inline void FLC(T &amp;A, int x){memset(A, x, sizeof(A));}\r\ntemplate&lt;class T0, class T1&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, int x){FLC(A0, x), FLC(A1, x);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2){FLC(A0), FLC(A1), FLC(A2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3){FLC(A0), FLC(A1), FLC(A2), FLC(A3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5, T6 &amp;A6){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5), FLC(A6);}\r\n\r\ntemplate&lt;class T&gt; inline void SRT(T &amp;A){sort(ALL(A));}\r\ntemplate&lt;class T, class C&gt; inline void SRT(T &amp;A, C B){sort(ALL(A), B);}\r\n\r\n\/** Add - On **\/\r\n\r\nconst int MOD = 1000000007;\r\nconst int INF = 0x7fffffff;\r\nconst DB EPS = 1e-9;\r\nconst DB OO = 1e15;\r\nconst DB PI = 3.14159265358979323846264;\/\/M_PI;\r\n\r\n\/\/ &lt;&lt;= ` 0. Daily Use .,\r\n\r\ntemplate&lt;class T&gt; inline void checkMin(T &amp;a,const T b){if (b&lt;a) a=b;}\r\ntemplate&lt;class T&gt; inline void checkMax(T &amp;a,const T b){if (b&gt;a) a=b;}\r\ntemplate &lt;class T, class C&gt; inline void checkMin(T&amp; a, const T b, C c){if (c(b,a)) a = b;}\r\ntemplate &lt;class T, class C&gt; inline void checkMax(T&amp; a, const T b, C c){if (c(a,b)) a = b;}\r\ntemplate&lt;class T&gt; inline T min(T a, T b, T c){return min(min(a, b), c);}\r\ntemplate&lt;class T&gt; inline T max(T a, T b, T c){return max(max(a, b), c);}\r\ntemplate&lt;class T&gt; inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}\r\ntemplate&lt;class T&gt; inline T sqr(T a){return a*a;}\r\ntemplate&lt;class T&gt; inline T cub(T a){return a*a*a;}\r\nint Ceil(int x, int y){return (x - 1) \/ y + 1;}\r\n\r\n\/\/ &lt;&lt;= ` 1. Bitwise Operation .,\r\n\r\ninline bool _1(int x, int i){return x &amp; 1&lt;&lt;i;}\r\ninline int _1(int i){return 1&lt;&lt;i;}\r\ninline int _U(int i){return _1(i) - 1;};\r\n\r\ninline int count_bits(int x){\r\n    x = (x &amp; 0x55555555) + ((x &amp; 0xaaaaaaaa) &gt;&gt; 1);\r\n    x = (x &amp; 0x33333333) + ((x &amp; 0xcccccccc) &gt;&gt; 2);\r\n    x = (x &amp; 0x0f0f0f0f) + ((x &amp; 0xf0f0f0f0) &gt;&gt; 4);\r\n    x = (x &amp; 0x00ff00ff) + ((x &amp; 0xff00ff00) &gt;&gt; 8);\r\n    x = (x &amp; 0x0000ffff) + ((x &amp; 0xffff0000) &gt;&gt; 16);\r\n    return x;\r\n}\r\n\r\ntemplate&lt;class T&gt; inline T low_bit(T x) {\r\n    return x &amp; -x;\r\n}\r\n\r\ntemplate&lt;class T&gt; inline T high_bit(T x) {\r\n    T p = low_bit(x);\r\n    while (p != x) x -= p, p = low_bit(x);\r\n    return p;\r\n}\r\n\r\n\/\/ &lt;&lt;= '9. Comutational Geometry .,\r\n\r\nstruct Po; struct Line; struct Seg;\r\n\r\ninline int sgn(DB x){return x &lt; -EPS ? -1 : x &gt; EPS;}\r\ninline int sgn(DB x, DB y){return sgn(x - y);}\r\n\r\nstruct Po{\r\n    DB x, y;\r\n    Po(DB _x = 0, DB _y = 0):x(_x), y(_y){}\r\n\r\n    friend istream&amp; operator &gt;&gt;(istream&amp; in, Po &amp;p){return in &gt;&gt; p.x &gt;&gt; p.y;}\r\n    friend ostream&amp; operator &lt;&lt;(ostream&amp; out, Po p){return out &lt;&lt; &quot;(&quot; &lt;&lt; p.x &lt;&lt; &quot;, &quot; &lt;&lt; p.y &lt;&lt; &quot;)&quot;;}\r\n\r\n    friend bool operator ==(Po, Po);\r\n    friend Po operator +(Po, Po);\r\n    friend Po operator -(Po, Po);\r\n    friend Po operator *(Po, DB);\r\n    friend Po operator \/(Po, DB);\r\n\r\n    bool operator &lt; (const Po &amp;rhs) const{return sgn(x, rhs.x) &lt; 0 || sgn(x, rhs.x) == 0 &amp;&amp; sgn(y, rhs.y) &lt; 0;}\r\n    Po&amp; operator +=(Po rhs){x += rhs.x, y += rhs.y;}\r\n    Po&amp; operator -=(Po rhs){x -= rhs.x, y -= rhs.y;}\r\n    Po&amp; operator *=(DB k){x *= k, y *= k;}\r\n    Po&amp; operator \/=(DB k){x \/= k, y \/= k;}\r\n\r\n    DB length_sqr(){return sqr(x) + sqr(y);}\r\n    DB length(){return sqrt(length_sqr());}\r\n\r\n    DB atan(){\r\n        return atan2(y, x);\r\n    }\r\n\r\n    void input(){\r\n        int _x, _y; scanf(&quot;%d %d&quot;, &amp;_x, &amp;_y);\r\n        x = _x, y = _y;\r\n    }\r\n};\r\n\r\nbool operator ==(Po a, Po b){return sgn(a.x - b.x) == 0 &amp;&amp; sgn(a.y - b.y) == 0;}\r\nPo operator +(Po a, Po b){return Po(a.x + b.x, a.y + b.y);}\r\nPo operator -(Po a, Po b){return Po(a.x - b.x, a.y - b.y);}\r\nPo operator *(Po a, DB k){return Po(a.x * k, a.y * k);}\r\nPo operator \/(Po a, DB k){return Po(a.x \/ k, a.y \/ k);}\r\n\r\nstruct Line{\r\n    Po a, b;\r\n    Line(Po _a = Po(), Po _b = Po()):a(_a), b(_b){}\r\n    Line(DB x0, DB y0, DB x1, DB y1):a(Po(x0, y0)), b(Po(x1, y1)){}\r\n    Line(Seg);\r\n};\r\n\r\nstruct Seg{\r\n    Po a, b;\r\n    Seg(Po _a = Po(), Po _b = Po()):a(_a), b(_b){}\r\n    Seg(DB x0, DB y0, DB x1, DB y1):a(Po(x0, y0)), b(Po(x1, y1)){}\r\n    Seg(Line l);\r\n\r\n    DB length(){return (b - a).length();}\r\n};\r\n\r\nLine::Line(Seg l):a(l.a), b(l.b){}\r\nSeg::Seg(Line l):a(l.a), b(l.b){}\r\n\r\n#define innerProduct dot\r\n#define scalarProduct dot\r\n#define dotProduct dot\r\n#define outerProduct det\r\n#define crossProduct det\r\n\r\ninline DB dot(DB x1, DB y1, DB x2, DB y2){return x1 * x2 + y1 * y2;}\r\ninline DB dot(Po a, Po b){return dot(a.x, b.y, b.x, b.y);}\r\ninline DB dot(Po p0, Po p1, Po p2){return dot(p1 - p0, p2 - p0);}\r\ninline DB dot(Line l1, Line l2){return dot(l1.b - l1.a, l2.b - l2.a);}\r\ninline DB det(DB x1, DB y1, DB x2, DB y2){return x1 * y2 - x2 * y1;}\r\ninline DB det(Po a, Po b){return det(a.x, a.y, b.x, b.y);}\r\ninline DB det(Po p0, Po p1, Po p2){return det(p1 - p0, p2 - p0);}\r\ninline DB det(Line l1, Line l2){return det(l1.b - l1.a, l2.b - l2.a);}\r\n\r\ntemplate&lt;class T1, class T2&gt; inline DB dist(T1 x, T2 y){return sqrt(dist_sqr(x, y));}\r\n\r\ninline DB dist_sqr(Po a, Po b){return sqr(a.x - b.x) + sqr(a.y - b.y);}\r\ninline DB dist_sqr(Po p, Line l){Po v0 = l.b - l.a, v1 = p - l.a; return sqr(fabs(det(v0, v1))) \/ v0.length_sqr();}\r\ninline DB dist_sqr(Po p, Seg l){\r\n    Po v0 = l.b - l.a, v1 = p - l.a, v2 = p - l.b;\r\n    if (sgn(dot(v0, v1)) * sgn(dot(v0, v2)) &lt;= 0) return dist_sqr(p, Line(l));\r\n    else return min(v1.length_sqr(), v2.length_sqr());\r\n}\r\n\r\ninline DB dist_sqr(Line l, Po p){\r\n    return dist_sqr(p, l);\r\n}\r\n\r\ninline DB dist_sqr(Line l1, Line l2){\r\n    if (sgn(det(l1, l2)) != 0) return 0;\r\n    return dist_sqr(l1.a, l2);\r\n}\r\ninline DB dist_sqr(Line l1, Seg l2){\r\n    Po v0 = l1.b - l1.a, v1 = l2.a - l1.a, v2 = l2.b - l1.a; DB c1 = det(v0, v1), c2 = det(v0, v2);\r\n    return sgn(c1) != sgn(c2) ? 0 : sqr(min(fabs(c1), fabs(c2))) \/ v0.length_sqr();\r\n}\r\n\r\ninline DB dist_sqr(Seg l, Po p){\r\n    return dist_sqr(p, l);\r\n}\r\n\r\ninline DB dist_sqr(Seg l1, Line l2){\r\n    return dist_sqr(l2, l1);\r\n}\r\n\r\nbool isIntersect(Seg l1, Seg l2){\r\n\r\n    \/\/if (l1.a == l2.a || l1.a == l2.b || l1.b == l2.a || l1.b == l2.b) return true;\r\n\r\n    return\r\n        min(l1.a.x, l1.b.x) &lt;= max(l2.a.x, l2.b.x) &amp;&amp;\r\n        min(l2.a.x, l2.b.x) &lt;= max(l1.a.x, l1.b.x) &amp;&amp;\r\n        min(l1.a.y, l1.b.y) &lt;= max(l2.a.y, l2.b.y) &amp;&amp;\r\n        min(l2.a.y, l2.b.y) &lt;= max(l1.a.y, l1.b.y) &amp;&amp;\r\n    sgn( det(l1.a, l2.a, l2.b) ) * sgn( det(l1.b, l2.a, l2.b) ) &lt;= 0 &amp;&amp;\r\n    sgn( det(l2.a, l1.a, l1.b) ) * sgn( det(l2.b, l1.a, l1.b) ) &lt;= 0;\r\n\r\n}\r\n\r\ninline DB dist_sqr(Seg l1, Seg l2){\r\n    if (isIntersect(l1, l2)) return 0;\r\n    else return min(dist_sqr(l1.a, l2), dist_sqr(l1.b, l2), dist_sqr(l2.a, l1), dist_sqr(l2.b, l1));\r\n}\r\n\r\ninline bool isOnseg(const Po &amp;p, const Seg &amp;l){\r\n    return sgn(det(p, l.a, l.b)) == 0 &amp;&amp;\r\n        sgn(l.a.x, p.x) * sgn(l.b.x, p.x) &lt;= 0 &amp;&amp; sgn(l.a.y, p.y) * sgn(l.b.y, p.y) &lt;= 0;\r\n}\r\n\r\ninline Po intersect(const Line &amp;l1, const Line &amp;l2){\r\n    return l1.a + (l1.b - l1.a) * (det(l2.a, l1.a, l2.b) \/ det(l2, l1));\r\n}\r\n\r\n\/\/ perpendicular foot\r\ninline Po intersect(const Po &amp; p, const Line &amp;l){\r\n    return intersect(Line(p, p + Po(l.a.y - l.b.y, l.b.x - l.a.x)), l);\r\n}\r\n\r\ninline Po rotate(Po p, DB alpha, Po o = Po()){\r\n    p.x -= o.x, p.y -= o .y;\r\n    return Po(p.x * cos(alpha) - p.y * sin(alpha), p.y * cos(alpha) + p.x * sin(alpha)) + o;\r\n}\r\n\r\n\r\n\/\/ &lt;&lt;= ' 0. I\/O Accelerator interface .,\r\n\r\ntemplate&lt;class T&gt; inline void RD(T &amp;x){\r\n    \/\/cin &gt;&gt; x;\r\n    scanf(&quot;%d&quot;, &amp;x);\r\n    \/\/char c; for (c = getchar(); c &lt; '0'; c = getchar()); x = c - '0'; for (c = getchar(); c &gt;= '0'; c = getchar()) x = x * 10 + c - '0';\r\n    \/\/char c; c = getchar(); x = c - '0'; for (c = getchar(); c &gt;= '0'; c = getchar()) x = x * 10 + c - '0';\r\n}\r\n\r\nconst DB no_solution = -1;\r\n\r\nint ____Case;\r\ntemplate&lt;class T&gt; inline void OT(const T &amp;x){\r\n    printf(&quot;Case #%d: &quot;, ++____Case);\r\n    printf(&quot;%d&quot;, x);\r\n    puts(&quot;&quot;);\r\n}\r\n\r\n\r\n\/* .................................................................................................................................. *\/\r\n\r\n\r\nconst int N = 50;\r\nbool Map&#x5B;N]&#x5B;N];\r\nbool exist&#x5B;100 + 5]&#x5B;100 + 5];\r\n\r\nint res;\r\n\r\n\r\nint main() {\r\n\r\n    freopen(&quot;D-small-practice.in&quot;, &quot;r&quot;, stdin);\r\n    freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n\r\n    int cases, cur;\r\n    int h, w, D;\r\n    int s, px, py, ii, jj, ox, oy, x0, y0;\r\n    double cx, cy, a, b, d;\r\n    bool destroyed;\r\n\r\n    Rush{\r\n\r\n        RD(h, w, D);\r\n        REP_2(i, j, h, w){\r\n            char t; RC(t); if (t == 'X') x0 = i, y0 = j;\r\n            Map&#x5B;i]&#x5B;j] = t != '#';\r\n        }\r\n\r\n        res = 0;\r\n\r\n        int i, j, k;\r\n\r\n        for (i=x0-1;Map&#x5B;i]&#x5B;y0];--i);\r\n        if (((x0-i)&lt;&lt;1)-1&lt;=D) ++res;\r\n\r\n        for (i=x0+1;Map&#x5B;i]&#x5B;y0];++i);\r\n        if (((i-x0)&lt;&lt;1)-1&lt;=D) ++res;\r\n\r\n        for (i=y0-1;Map&#x5B;x0]&#x5B;i];--i);\r\n        if (((y0-i)&lt;&lt;1)-1&lt;=D) ++res;\r\n\r\n        for (i=y0+1;Map&#x5B;x0]&#x5B;i];++i);\r\n        if (((i-y0)&lt;&lt;1)-1&lt;= D) ++res;\r\n\r\n\r\n\t\tRST(exist);\r\n\r\n        FOR(ii, -D+1, D) if (ii) FOR(jj, -D+1, D) if (jj &amp;&amp; sqr(ii)+sqr(jj)&lt;=sqr(D)){\r\n\r\n            k = abs(__gcd(ii, jj)), i = ii \/ k, j = jj \/ k;\r\n            if (exist&#x5B;i + 50]&#x5B;j + 50]) continue;\r\n\r\n            i = ii, j = jj, cx = x0 + 0.5, cy = y0 + 0.5, d = 0, destroyed = false; do{\r\n\r\n                if (i &lt; 0) a = (cx - (int)(cx - EPS)) \/ -i;\r\n                else a = ((int)(cx + 1 + EPS) - cx) \/ i;\r\n\r\n                if (j &lt; 0) b = (cy - (int)(cy - EPS)) \/ -j;\r\n                else b = ((int)(cy + 1 + EPS) - cy) \/ j;\r\n\r\n                checkMin(a, b);\r\n\r\n                if (d + a &gt; 1) break;\r\n\r\n                d += a, cx += a * i, cy += a * j;\r\n                px = cx + EPS, py = cy + EPS;\r\n\r\n                if (cx - px &lt; EPS &amp;&amp; cy - py &lt; EPS) {\r\n                    if (i &lt; 0) ox = px--; else ox = px-1;\r\n                    if (j &lt; 0) oy = py--; else oy = py-1;\r\n                    if (!Map&#x5B;px]&#x5B;py]) {\r\n                        destroyed = true;\r\n                        if (!Map&#x5B;ox]&#x5B;py]) j = -j, destroyed = false;\r\n                        if (!Map&#x5B;px]&#x5B;oy]) i = -i, destroyed = false;\r\n                    }\r\n                }\r\n                else if (cx - px &lt; EPS) {\r\n                    if (i &lt; 0) --px;\r\n                    if (!Map&#x5B;px]&#x5B;py]) i = -i;\r\n                }\r\n                else if (cy - py &lt; EPS) {\r\n                    if (j &lt; 0) --py;\r\n                    if (!Map&#x5B;px]&#x5B;py]) j = -j;\r\n                }\r\n\r\n            } while (!destroyed);\r\n\r\n            if (destroyed) continue;\r\n\r\n            a = (x0 + 0.5 - cx) \/ i, b = (y0 + 0.5 - cy) \/ j;\r\n            if (fabs(d + a - 1) &lt; EPS &amp;&amp; fabs(d + b - 1) &lt; EPS) {\r\n                k = abs(__gcd(ii, jj)), i = ii \/ k, j = jj \/ k;\r\n                ++res, exist&#x5B;i + 50]&#x5B;j + 50] = true;\r\n            }\r\n        }\r\n\r\n        OT(res);\r\n    }\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Brief description: Problem D. Hall of Mirrors \u7ed9\u5b9a\u4e00\u4e2a\u955c\u4e2d\u4e16\u754c.. . \u95ee\u70b9\u5149\u6e90\u5904\u6709\u591a\u5c11\u675f\u5149\u7ebf\u53ef\u4ee5\u5728 D \u5c04\u7a0b\u5185\u53cd\u5c04\u56de\u6765\u3002 \uff08 D<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[67],"tags":[68,25],"class_list":["post-183","post","type-post","status-publish","format-standard","hentry","category-google-code-jam","tag-68","tag-25"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-2X","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=183"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/183\/revisions"}],"predecessor-version":[{"id":184,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/183\/revisions\/184"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}