{"id":274,"date":"2012-06-27T18:44:52","date_gmt":"2012-06-27T10:44:52","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=274"},"modified":"2012-07-04T02:19:38","modified_gmt":"2012-07-03T18:19:38","slug":"srm-547","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/srm-547\/","title":{"rendered":"SRM 547"},"content":{"rendered":"<h3>Brief description: <\/h3>\n<p>Problem 250. Pillars<br \/>\n\u3002\u3002\u8981\u5728\u4e24\u9762\u5899\u4e4b\u95f4\u67b6\u4e00\u4e2a\u68af\u5b50\uff0c\u4e24\u9762\u5899\u9ad8\u5ea6\u7686\u4e3a\u6574\u6570\uff0c\u5747\u5300\u9009\u81ea [1, A] \u548c [1, B] \u4e4b\u95f4\u3002<br \/>\n\u3002\u4e2d\u95f4\u8ddd\u79bb\u4e3a w\uff0c\u95ee\u68af\u5b50\u671f\u671b\u7684\u957f\u5ea6\u3002<br \/>\n(\u3002\u30021 \u2264 A, B \u2264 100, 000 \u3002\u3002\u3002) <\/p>\n<p>Problem 500. RectangularSum<br \/>\n\u7ed9\u5b9a\u4e00\u4e2a\u9010\u884c\u9010\u5217\u4f9d\u6b21\u586b {0, 1, 2, 3, 4, &#8230; nm-1} \u7684 n \u00d7 m \u77e9\u9635\u3002\u3002<br \/>\n\u3002\u3002\u3002\u95ee\u6240\u6709\u548c\u7b49\u4e8e S \u7684\u5b50\u77e9\u9635\u4e2d\uff0c\u9762\u79ef\u6700\u5c0f\u7684\u662f\u591a\u5c11\u3002<br \/>\n(\u3002\u30021 \u2264 n, m \u2264 100, 000 \u3002\u3002\u30021 \u2264 S \u2264 100, 000, 000, 000\u3002\u3002\u3002) <\/p>\n<p>Problem 1000. MaximalTriangle<br \/>\n\u95ee\u6b63 n \u8fb9\u5f62\u7684\u4e09\u89d2\u5256\u5206\u4e2d\uff0c\u6709\u591a\u5c11\u79cd\u5256\u5206\u662f\u53ef\u4ee5\u4ea7\u751f\u4e00\u4e2a\u9762\u79ef\u6700\u5927\u7684\u5927\u4e09\u89d2\u5f62\u7684\u3002<br \/>\n(\u3002\u30023 \u2264 n \u2264 444 \u3002\u3002\u3002\uff09<br \/>\n<!--more--><\/p>\n<h3>Analysis: <\/h3>\n<p>Problem 250. Pillars<br \/>\n\u5206\u7ec4\u8ba1\u6570\uff0c\u679a\u4e3e\u9ad8\u5ea6\u5dee\u3002<\/p>\n<p>Problem 500. RectangularSum<br \/>\n\u3002\u3002\u8fd9\u9898\u7684\u96be\u70b9\u4e3b\u8981\u5728 O(1) \u65f6\u95f4\u5185\u5b9e\u73b0\u4e00\u4e2a\u540d\u4e3a bool check(x, y); \u7684\u51fd\u6570; \u6765\u5224\u65ad\u957f\u5bbd\u4e3a x, y \uff0c\u548c\u4e3a S \u7684\u5b50\u77e9\u9635\u662f\u5426\u5b58\u5728\u3002\u3002<br \/>\n\u8fd9\u4e2a\u5148\u628a\u6574\u4e2a\u5b50\u77e9\u9635\u79fb\u52a8\u5230\u6700\u4e0a\u89d2\u3002\u3002\u7136\u540e\u901a\u8fc7\u5224\u65ad\u4f4d\u79fb\u662f\u5426\u5408\u6cd5\u5c31\u884c\u4e86\u3002\u3002<br \/>\n\u3002\u3002\u3002\u7136\u540e\u5916\u56f4\u7528\u4e00\u4e2a\u5806\u3002\u3002\u7ef4\u62a4\u4e00\u5806\u4e0b\u6807\u3002\u3002\u8fd9\u6837\u8c8c\u4f3c\u590d\u6742\u5ea6\u662f O(n^2logn)\u3002\u3002\u7136\u540e\u968f\u4fbf\u52a0\u4e86\u70b9\u526a\u679d\u5c31\u8fc7\u6389\u4e86\u3002\u3002<\/p>\n<p>Problem 1000. MaximalTriangle<br \/>\n\u3002\u3002\u6ca1\u4ec0\u4e48\u597d\u7684\u60f3\u6cd5\u3002\u3002\u57fa\u672c\u601d\u60f3\u53ea\u80fd\u662f\u5148\u79bb\u6563\u5316\u4e09\u89d2\u5f62\u9762\u79ef\u3002\u7136\u540e\u679a\u4e3e\u4e2d\u95f4\u7684\u5927\u4e09\u89d2\u5f62\u3002\u3002\u7136\u540e\u4ea7\u751f\u4e09\u4e2a\u65b9\u5411\u7684\u9012\u5f52\uff1f\u3002\u3002<br \/>\n\u3002\u3002f(i, s) \u8868\u793a\u4e00\u4e2a i \u4e2a\u5b9a\u70b9\u7684\u5b50\u533a\u57df\u4e2d\uff0c\u6240\u6709\u4e0d\u5305\u542b\u9762\u79ef\u5927\u4e8e\u7b49\u4e8e s \u7684\u4e09\u89d2\u5f62\u7684\u5256\u5206\u6570\u3002\u3002\u3002\u3002\u3002\u3002<br \/>\n\u8c8c\u4f3c\u603b\u7684\u590d\u6742\u5ea6 O(n4) \u3002\u3002\uff08\u5171 O(n3) \u79cd\u72b6\u6001\u3002\u3002\u8f6c\u79fb\u3002O(n)\u3002\u3002\u3002\u3002<br \/>\n\uff08\u4e0d\u8fc7\u597d\u50cf\u5927\u5bb6\u90fd\u662f\u8fd9\u6837\u8fc7\u7684\u3002\u3002\u5c31\u662f\u52a0\u5e38\u6570\u4f18\u5316\u3002\u3002 \/$:o~o <\/p>\n<pre class=\"brush: cpp; collapse: true; first-line: 1; light: false; title: Problem 250. Pillars.cpp; toolbar: true; notranslate\" title=\"Problem 250. Pillars.cpp\">\r\nDB sqr(DB x){\r\n    return x * x;\r\n}\r\n\r\nclass Pillars {\r\npublic:\r\n\tdouble getExpectedLength(int w, int x, int y) {\r\n\r\n        DB q = min(x, y), p = w * q, pp, qq;\r\n        \r\n        REP_1_C(i, max(x, y)){\r\n            qq = min(x, max(0, y - i)), pp = sqrt(sqr(w) +  sqr(i)) * qq;\r\n            p += pp, q += qq;\r\n            qq = min(max(0, x - i), y), pp = sqrt(sqr(w) +  sqr(i)) * qq;\r\n            p += pp, q += qq;\r\n        }\r\n        \r\n        return p \/ q;\r\n\t}\r\n};\r\n<\/pre>\n<pre class=\"brush: cpp; collapse: true; first-line: 1; light: false; title: Problem 500. RectangularSum.cpp; toolbar: true; notranslate\" title=\"Problem 500. RectangularSum.cpp\">\r\nLL w, h, S; bool flag;\r\n\r\nbool check(LL x, LL y){\r\n\r\n    flag = false;\r\n    LL A = x * y, B = A * (y - 1), C = x*(x-1) * (y*w);\r\n    LL S = ::S - B - C; if (S &lt; 0) return false; flag = true;\r\n    LL d = S \/ (A*2); if (d * (A*2) != S) return false;\r\n    LL up = (h - x + 1) * w;\r\n    return d &lt; up &amp;&amp; d % w &lt;= w - y;\r\n}\r\n\r\nclass RectangularSum {\r\npublic:\r\n\tlong long minimalArea(LL h, LL w, LL S) {\r\n\t    ::h = h, ::w = w, ::S = S, ::S &lt;&lt;= 1;\r\n\r\n\t\tpriority_queue&lt;PLI, vector&lt;PLI&gt;, greater&lt;PLI&gt; &gt; Q;\r\n\t\tREP_1(i, h) Q.push(MP((LL)i, i));\r\n\r\n#define s first\r\n#define x second\r\n\r\n\t\twhile (!Q.empty()){\r\n\t\t    PLI cur = Q.top(); LL y = cur.s \/ cur.x; Q.pop();\r\n\t\t    if (check(cur.x, y)) return cur.s;\r\n\t\t    if (y &lt; w &amp;&amp; flag) Q.push(MP(cur.s + cur.x, cur.x));\r\n\t\t}\r\n\r\n\t\treturn -1;\r\n\t}\r\n};\r\n<\/pre>\n<pre class=\"brush: cpp; collapse: true; first-line: 1; light: false; title: Problem 1000. MaximalTriangle.cpp; toolbar: true; notranslate\" title=\"Problem 1000. MaximalTriangle.cpp\">\r\n#define LOCAL\r\n\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\n\r\ntemplate&lt;class T&gt; inline void CLR(priority_queue&lt;T, vector&lt;T&gt;, less&lt;T&gt; &gt; &amp;Q){\r\n    while (!Q.empty()) Q.pop();\r\n}\r\n\r\ntemplate&lt;class T&gt; inline void CLR(priority_queue&lt;T, vector&lt;T&gt;, greater&lt;T&gt; &gt; &amp;Q){\r\n    while (!Q.empty()) Q.pop();\r\n}\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\nint MOD = 1000000007;\r\nconst int INF = 0x3f3f3f3f;\r\nconst LL INF_64 = 0x3f3f3f3f3f3f3f3fLL;\r\nconst DB EPS = 1e-11;\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 max(T a, T b, T c, T d){return max(min(a, b), max(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\ninline bool _1(int x, int i){return x &amp; 1&lt;&lt;i;}\r\ninline bool _1(LL x, int i){return x &amp; 1LL&lt;&lt;i;}\r\ninline LL _1(int i){return 1LL&lt;&lt;i;}\r\n\/\/inline int _1(int i){return 1&lt;&lt;i;}\r\ninline LL _U(int i){return _1(i) - 1;};\r\n\/\/inline int _U(int i){return _1(i) - 1;};\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\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\ninline int count_bits(LL x){\r\n    x = (x &amp; 0x5555555555555555LL) + ((x &amp; 0xaaaaaaaaaaaaaaaaLL) &gt;&gt; 1);\r\n    x = (x &amp; 0x3333333333333333LL) + ((x &amp; 0xccccccccccccccccLL) &gt;&gt; 2);\r\n    x = (x &amp; 0x0f0f0f0f0f0f0f0fLL) + ((x &amp; 0xf0f0f0f0f0f0f0f0LL) &gt;&gt; 4);\r\n    x = (x &amp; 0x00ff00ff00ff00ffLL) + ((x &amp; 0xff00ff00ff00ff00LL) &gt;&gt; 8);\r\n    x = (x &amp; 0x0000ffff0000ffffLL) + ((x &amp; 0xffff0000ffff0000LL) &gt;&gt; 16);\r\n    x = (x &amp; 0x00000000ffffffffLL) + ((x &amp; 0xffffffff00000000LL) &gt;&gt; 32);\r\n    return x;\r\n}\r\n\r\nint reverse_bits(int x){\r\n    x = ((x &gt;&gt; 1) &amp; 0x55555555) | ((x &lt;&lt; 1) &amp; 0xaaaaaaaa);\r\n    x = ((x &gt;&gt; 2) &amp; 0x33333333) | ((x &lt;&lt; 2) &amp; 0xcccccccc);\r\n    x = ((x &gt;&gt; 4) &amp; 0x0f0f0f0f) | ((x &lt;&lt; 4) &amp; 0xf0f0f0f0);\r\n    x = ((x &gt;&gt; 8) &amp; 0x00ff00ff) | ((x &lt;&lt; 8) &amp; 0xff00ff00);\r\n    x = ((x &gt;&gt;16) &amp; 0x0000ffff) | ((x &lt;&lt;16) &amp; 0xffff0000);\r\n    return x;\r\n}\r\n\r\nLL reverse_bits(LL x){\r\n    x = ((x &gt;&gt; 1) &amp; 0x5555555555555555LL) | ((x &lt;&lt; 1) &amp; 0xaaaaaaaaaaaaaaaaLL);\r\n    x = ((x &gt;&gt; 2) &amp; 0x3333333333333333LL) | ((x &lt;&lt; 2) &amp; 0xccccccccccccccccLL);\r\n    x = ((x &gt;&gt; 4) &amp; 0x0f0f0f0f0f0f0f0fLL) | ((x &lt;&lt; 4) &amp; 0xf0f0f0f0f0f0f0f0LL);\r\n    x = ((x &gt;&gt; 8) &amp; 0x00ff00ff00ff00ffLL) | ((x &lt;&lt; 8) &amp; 0xff00ff00ff00ff00LL);\r\n    x = ((x &gt;&gt;16) &amp; 0x0000ffff0000ffffLL) | ((x &lt;&lt;16) &amp; 0xffff0000ffff0000LL);\r\n    x = ((x &gt;&gt;32) &amp; 0x00000000ffffffffLL) | ((x &lt;&lt;32) &amp; 0xffffffff00000000LL);\r\n    return x;\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 = (LL)a * b % MOD;}\r\ninline int pdt(int a, int b){return (LL)a * b % MOD;}\r\ninline int pdt(int a, int b, int c){return pdt(pdt(a, b), c);}\r\ninline int sqr_M(int a){return pdt(a, a);}\r\n\r\ninline int pow(int a, int b){\r\n    int c = 1;\r\n    while (b) {\r\n        if (b&amp;1) MUL(c, a);\r\n        MUL(a, a), b &gt;&gt;= 1;\r\n    }\r\n    return c;\r\n}\r\n\r\ntemplate&lt;class T&gt;\r\ninline int pow(T a, int b){\r\n    T c(1);\r\n    while (b) {\r\n        if (b&amp;1) MUL(c, a);\r\n        MUL(a, a), b &gt;&gt;= 1;\r\n    }\r\n    return c;\r\n}\r\n\r\ninline int _I(int b){\r\n    int a = MOD, x1 = 0, x2 = 1, q;\r\n    while (true){\r\n        q = a \/ b, a %= b;\r\n        if (!a) return (x2 + MOD) % MOD;\r\n        DEC(x1, pdt(q, x2));\r\n\r\n        q = b \/ a, b %= a;\r\n        if (!b) return (x1 + MOD) % MOD;\r\n        DEC(x2, pdt(q, x1));\r\n    }\r\n}\r\n\r\ninline void DIV(int &amp;a, int b){MUL(a, _I(b));}\r\ninline int qtt(int a, int b){return pdt(a, _I(b));}\r\n\r\ninline int sum(int a, int b, int MOD){\r\n    a += b; if (a &gt;= MOD) a -= MOD;\r\n    return a;\r\n}\r\n\r\ninline int phi(int n){\r\n    int res = n;\r\n    for (int i=2;sqr(i)&lt;=n;++i) if (!(n%i)){\r\n        DEC(res, qtt(res, i));\r\n        do{n \/= i;} while(!(n%i));\r\n    }\r\n    if (n != 1)\r\n        DEC(res, qtt(res, n));\r\n    return res;\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\ninline bool equ(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 operator-() const{return Po(-x, -y);}\r\n    Po&amp; operator +=(Po rhs){x += rhs.x, y += rhs.y; return *this;}\r\n    Po&amp; operator -=(Po rhs){x -= rhs.x, y -= rhs.y; return *this;}\r\n    Po&amp; operator *=(DB k){x *= k, y *= k; return *this;}\r\n    Po&amp; operator \/=(DB k){x \/= k, y \/= k; return *this;}\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        scanf(&quot;%lf %lf&quot;, &amp;x, &amp;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 *(DB k, Po a){return a * 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, a.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){return dist_sqr(p, l);}\r\ninline DB dist_sqr(Seg l, Po p){return dist_sqr(p, l);}\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\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\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;= ' A. Random Event ..\r\n\r\ninline int rand32(){return (bool(rand() &amp; 1) &lt;&lt; 30) | (rand() &lt;&lt; 15) + rand();}\r\ninline int random32(int l, int r){return rand32() % (r - l + 1) + l;}\r\ninline int random(int l, int r){return rand() % (r - l + 1) + l;}\r\nint dice(){return rand() % 6;}\r\nbool coin(){return rand() % 2;}\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\ntemplate&lt;class T&gt; inline void OT(const T &amp;x){\r\n    \/\/printf(&quot;%d\\n&quot;, x);\r\n    cout &lt;&lt; x &lt;&lt; endl;\r\n}\r\n\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 495, AN = 17000;\r\n\r\nPo P&#x5B;N]; DB A&#x5B;N]&#x5B;N]; int p&#x5B;N]&#x5B;N]; VD L;\r\nint cp&#x5B;N], dp&#x5B;N]&#x5B;AN];\r\nint n;\r\n\r\nDB area(int _a, int _b, int _c){\r\n\r\n    \/\/return abs(det(C&#x5B;0], C&#x5B;_a]) + det(C&#x5B;_a], C&#x5B;_b]) + det(C&#x5B;_b], C&#x5B;0]));\r\n\r\n    DB a = dist(P&#x5B;0], P&#x5B;_a]), b = dist(P&#x5B;0], P&#x5B;_b]), c = dist(P&#x5B;0], P&#x5B;_c]);\r\n    DB p = (a + b + c) \/ 2;\r\n    return sqrt(p * (p - a) * (p - b) * (p - c));\r\n}\r\n\r\nint g(int len, int limit){\r\n\r\n    if (len &lt;= 1) return 1;\r\n\r\n    int &amp;res = dp&#x5B;len]&#x5B;limit];\r\n\r\n    if (res == -1){\r\n        if (p&#x5B;n-len]&#x5B;len\/2] &lt; limit){\r\n            res = cp&#x5B;len - 1];\r\n        }\r\n        else {\r\n            LL buf = 0; for (int i=1;2*i&lt;=len&amp;&amp;p&#x5B;n-len]&#x5B;i]&lt;limit;++i){\r\n                buf += (LL) g(i, limit) * g(len - i, limit);\r\n                if (buf &gt;= INF_64) buf %= MOD;\r\n            }\r\n            buf %= MOD, res = buf, INC(res, res);\r\n        }\r\n    }\r\n\r\n    return res;\r\n}\r\n\r\nint f(int a, int b){\r\n    return pdt(g(a, p&#x5B;a]&#x5B;b]), g(b, p&#x5B;a]&#x5B;b]), g(n-a-b, p&#x5B;a]&#x5B;b]));\r\n}\r\n\r\nclass MaximalTriangle {\r\npublic:\r\n\tint howMany(int n, int z) {\r\n\r\n\t    MOD = z, RST(cp), cp&#x5B;0] = 1 % z; REP_1(i, n){\r\n\t        REP_C(j, (i+1)\/2) INC(cp&#x5B;i], pdt(cp&#x5B;j], cp&#x5B;i-1-j])); INC(cp&#x5B;i], cp&#x5B;i]);\r\n\t        if (i&amp;1) DEC(cp&#x5B;i], sqr_M(cp&#x5B;i\/2]));\r\n\t    }\r\n\r\n\t    ::n = n; REP(i, n) P&#x5B;i] = Po(cos(2.0*PI*i\/n), sin(2.0*PI*i\/n));\r\n\r\n\t    CLR(L); FOR(i, 1, n) FOR(j, 1, n-i){\r\n\t        A&#x5B;i]&#x5B;j] = area(i, j, n - i - j);\r\n\t        L.PB(A&#x5B;i]&#x5B;j]);\r\n        }\r\n\r\n        SRT(L); L.resize(unique(ALL(L), equ) - L.begin());\r\n\r\n        RST(p); FOR(i, 1, n) FOR(j, 1, n - i)\r\n            p&#x5B;i]&#x5B;j] = lower_bound(ALL(L), A&#x5B;i]&#x5B;j] - EPS) - L.begin();\r\n\r\n        int t&#x5B;] = {(n \/ 3) % MOD, n % MOD, (LL) 2 * n % MOD};\r\n        FLC(dp, -1); int res = 0; REP(a, n) FOR_1_C(b, a, (n - a) \/ 2){\r\n            INC(res, pdt(f(a, b), t&#x5B;(a != b) + (b != n - a - b)]));\r\n        }\r\n\r\n\t    return res;\r\n\t}\r\n};\r\n\r\n\r\n\/\/ BEGIN CUT HERE\r\nnamespace moj_harness {\r\n\tint run_test_case(int);\r\n\tvoid run_test(int casenum = -1, bool quiet = false) {\r\n\t\tif (casenum != -1) {\r\n\t\t\tif (run_test_case(casenum) == -1 &amp;&amp; !quiet) {\r\n\t\t\t\tcerr &lt;&lt; &quot;Illegal input! Test case &quot; &lt;&lt; casenum &lt;&lt; &quot; does not exist.&quot; &lt;&lt; endl;\r\n\t\t\t}\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tint correct = 0, total = 0;\r\n\t\tfor (int i=0;; ++i) {\r\n\t\t\tint x = run_test_case(i);\r\n\t\t\tif (x == -1) {\r\n\t\t\t\tif (i &gt;= 100) break;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tcorrect += x;\r\n\t\t\t++total;\r\n\t\t}\r\n\r\n\t\tif (total == 0) {\r\n\t\t\tcerr &lt;&lt; &quot;No test cases run.&quot; &lt;&lt; endl;\r\n\t\t} else if (correct &lt; total) {\r\n\t\t\tcerr &lt;&lt; &quot;Some cases FAILED (passed &quot; &lt;&lt; correct &lt;&lt; &quot; of &quot; &lt;&lt; total &lt;&lt; &quot;).&quot; &lt;&lt; endl;\r\n\t\t} else {\r\n\t\t\tcerr &lt;&lt; &quot;All &quot; &lt;&lt; total &lt;&lt; &quot; tests passed!&quot; &lt;&lt; endl;\r\n\t\t}\r\n\t}\r\n\r\n\tint verify_case(int casenum, const int &amp;expected, const int &amp;received, clock_t elapsed) {\r\n\t\tcerr &lt;&lt; &quot;Example &quot; &lt;&lt; casenum &lt;&lt; &quot;... &quot;;\r\n\r\n\t\tstring verdict;\r\n\t\tvector&lt;string&gt; info;\r\n\t\tchar buf&#x5B;100];\r\n\r\n\t\tif (elapsed &gt; CLOCKS_PER_SEC \/ 200) {\r\n\t\t\tsprintf(buf, &quot;time %.2fs&quot;, elapsed * (1.0\/CLOCKS_PER_SEC));\r\n\t\t\tinfo.push_back(buf);\r\n\t\t}\r\n\r\n\t\tif (expected == received) {\r\n\t\t\tverdict = &quot;PASSED&quot;;\r\n\t\t} else {\r\n\t\t\tverdict = &quot;FAILED&quot;;\r\n\t\t}\r\n\r\n\t\tcerr &lt;&lt; verdict;\r\n\t\tif (!info.empty()) {\r\n\t\t\tcerr &lt;&lt; &quot; (&quot;;\r\n\t\t\tfor (int i=0; i&lt;(int)info.size(); ++i) {\r\n\t\t\t\tif (i &gt; 0) cerr &lt;&lt; &quot;, &quot;;\r\n\t\t\t\tcerr &lt;&lt; info&#x5B;i];\r\n\t\t\t}\r\n\t\t\tcerr &lt;&lt; &quot;)&quot;;\r\n\t\t}\r\n\t\tcerr &lt;&lt; endl;\r\n\r\n\t\tif (verdict == &quot;FAILED&quot;) {\r\n\t\t\tcerr &lt;&lt; &quot;    Expected: &quot; &lt;&lt; expected &lt;&lt; endl;\r\n\t\t\tcerr &lt;&lt; &quot;    Received: &quot; &lt;&lt; received &lt;&lt; endl;\r\n\t\t}\r\n\r\n\t\treturn verdict == &quot;PASSED&quot;;\r\n\t}\r\n\r\n\tint run_test_case(int casenum) {\r\n\t\tswitch (casenum) {\r\n\t\tcase 0: {\r\n\t\t\tint n                     = 428;\r\n\t\t\tint z                     = 900000005;\r\n\t\t\tint expected__            = 180276168;\r\n\r\n\t\t\tclock_t start__           = clock();\r\n\t\t\tint received__            = MaximalTriangle().howMany(n, z);\r\n\t\t\treturn verify_case(casenum, expected__, received__, clock()-start__);\r\n\t\t}\r\n\t\tcase 1: {\r\n\t\t\tint n                     = 5;\r\n\t\t\tint z                     = 100;\r\n\t\t\tint expected__            = 5;\r\n\r\n\t\t\tclock_t start__           = clock();\r\n\t\t\tint received__            = MaximalTriangle().howMany(n, z);\r\n\t\t\treturn verify_case(casenum, expected__, received__, clock()-start__);\r\n\t\t}\r\n\t\tcase 2: {\r\n\t\t\tint n                     = 6;\r\n\t\t\tint z                     = 1000003;\r\n\t\t\tint expected__            = 2;\r\n\r\n\t\t\tclock_t start__           = clock();\r\n\t\t\tint received__            = MaximalTriangle().howMany(n, z);\r\n\t\t\treturn verify_case(casenum, expected__, received__, clock()-start__);\r\n\t\t}\r\n\t\tcase 3: {\r\n\t\t\tint n                     = 10;\r\n\t\t\tint z                     = 1000000000;\r\n\t\t\tint expected__            = 1010;\r\n\r\n\t\t\tclock_t start__           = clock();\r\n\t\t\tint received__            = MaximalTriangle().howMany(n, z);\r\n\t\t\treturn verify_case(casenum, expected__, received__, clock()-start__);\r\n\t\t}\r\n\t\tcase 4: {\r\n\t\t\tint n                     = 15;\r\n\t\t\tint z                     = 1000000000;\r\n\t\t\tint expected__            = 714340;\r\n\r\n\t\t\tclock_t start__           = clock();\r\n\t\t\tint received__            = MaximalTriangle().howMany(n, z);\r\n\t\t\treturn verify_case(casenum, expected__, received__, clock()-start__);\r\n\t\t}\r\n\t\tcase 5: {\r\n\t\t\tint n                     = 100;\r\n\t\t\tint z                     = 987654321;\r\n\t\t\tint expected__            = 308571232;\r\n\r\n\t\t\tclock_t start__           = clock();\r\n\t\t\tint received__            = MaximalTriangle().howMany(n, z);\r\n\t\t\treturn verify_case(casenum, expected__, received__, clock()-start__);\r\n\t\t}\r\n\r\n\t\t\/\/ custom cases\r\n\r\n\/*      case 6: {\r\n\t\t\tint n                     = ;\r\n\t\t\tint z                     = ;\r\n\t\t\tint expected__            = ;\r\n\r\n\t\t\tclock_t start__           = clock();\r\n\t\t\tint received__            = MaximalTriangle().howMany(n, z);\r\n\t\t\treturn verify_case(casenum, expected__, received__, clock()-start__);\r\n\t\t}*\/\r\n\/*      case 7: {\r\n\t\t\tint n                     = ;\r\n\t\t\tint z                     = ;\r\n\t\t\tint expected__            = ;\r\n\r\n\t\t\tclock_t start__           = clock();\r\n\t\t\tint received__            = MaximalTriangle().howMany(n, z);\r\n\t\t\treturn verify_case(casenum, expected__, received__, clock()-start__);\r\n\t\t}*\/\r\n\/*      case 8: {\r\n\t\t\tint n                     = ;\r\n\t\t\tint z                     = ;\r\n\t\t\tint expected__            = ;\r\n\r\n\t\t\tclock_t start__           = clock();\r\n\t\t\tint received__            = MaximalTriangle().howMany(n, z);\r\n\t\t\treturn verify_case(casenum, expected__, received__, clock()-start__);\r\n\t\t}*\/\r\n\t\tdefault:\r\n\t\t\treturn -1;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nint main(int argc, char *argv&#x5B;]) {\r\n\tif (argc == 1) {\r\n\t\tmoj_harness::run_test();\r\n\t} else {\r\n\t\tfor (int i=1; i&lt;argc; ++i)\r\n\t\t\tmoj_harness::run_test(atoi(argv&#x5B;i]));\r\n\t}\r\n}\r\n\/\/ END CUT HERE\r\n\r\n<\/pre>\n<h3>External link: <\/h3>\n<p><a href=\"http:\/\/apps.topcoder.com\/wiki\/display\/tc\/SRM+547\">http:\/\/apps.topcoder.com\/wiki\/display\/tc\/SRM+547<\/a><br \/>\n<a href=\"http:\/\/community.topcoder.com\/stat?c=coder_room_stats&#038;rd=14739&#038;cr=22727863\">http:\/\/community.topcoder.com\/stat?c=coder_room_stats&#038;rd=14739&#038;cr=22727863<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description: Problem 250. Pillars \u3002\u3002\u8981\u5728\u4e24\u9762\u5899\u4e4b\u95f4\u67b6\u4e00\u4e2a\u68af\u5b50\uff0c\u4e24\u9762\u5899\u9ad8\u5ea6\u7686\u4e3a\u6574\u6570\uff0c\u5747\u5300\u9009\u81ea [1, A] \u548c [1, B] \u4e4b\u95f4\u3002 \u3002\u4e2d\u95f4\u8ddd\u79bb\u4e3a w\uff0c\u95ee\u68af\u5b50\u671f\u671b\u7684\u957f\u5ea6\u3002 (\u3002\u30021 \u2264 A, B \u2264 100, 000 \u3002\u3002\u3002) Problem 500. RectangularSum \u7ed9\u5b9a\u4e00\u4e2a\u9010\u884c\u9010\u5217\u4f9d\u6b21\u586b {0, 1, 2, 3, 4, &#8230; nm-1} \u7684 n \u00d7 m \u77e9\u9635\u3002\u3002 \u3002\u3002\u3002\u95ee\u6240\u6709\u548c\u7b49\u4e8e S \u7684\u5b50\u77e9\u9635\u4e2d\uff0c\u9762\u79ef\u6700\u5c0f\u7684\u662f\u591a\u5c11\u3002 (\u3002\u30021 \u2264 n, m \u2264 100, 000 \u3002\u3002\u30021 \u2264 S \u2264 100, 000, 000, [&hellip;]<\/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":[17],"tags":[],"class_list":["post-274","post","type-post","status-publish","format-standard","hentry","category-topcoder"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-4q","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/274","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=274"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/274\/revisions"}],"predecessor-version":[{"id":284,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/274\/revisions\/284"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}